Takeshi, who loves hot springs, is planning a trip to a hot spring resort on his next long vacation. I would like to travel by connecting to a long-distance bus and reach my destination with as little money as possible. Takeshi, who has savings but is unwilling to pay, decided to consult with his grandfather. The grandfather, who was impressed by the plan, gave Takeshi a special ticket.

The ticket was that you could ride two consecutive sections of a long-distance bus only once for free. Depending on how you use it, you can expect a considerable reduction in travel costs, but you need to make a solid plan in order to achieve a greater effect.

A total of n departure points, destinations, and relay points, and m lines connecting the two points are given. Each point is assigned a number from 1 to n. The starting point is 1 and the destination is n. Route information is represented by the two points a and b that connect the route and its fare c. Due to the special ticket validity, you can pass two consecutive lines from any point at no charge. However, passing through the destination on the way does not mean that you have reached the destination.

Create a program that outputs the minimum fare by inputting the total number of departure points, destinations, and relay points n, the number of routes m, and the information of each route. However, there must always be a route from the origin to the destination.



input

Given multiple datasets. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:


n m
a1 b1 c1
a2 b2 c2
::
am bm cm


The first line gives the total number of origins, destinations, and transit points n (2 ≤ n ≤ 100) and the number of routes m (1 ≤ m ≤ 300). The following m lines give information for each line ai, bi, ci (1 ≤ ci ≤ 1000).

The number of datasets does not exceed 40.

output

Prints the minimum charge on one line for each input dataset.

Example

Input

2 1
1 2 5
3 2
1 2 5
2 3 5
6 9
1 2 7
1 3 9
1 5 14
2 3 10
2 4 15
3 4 11
3 5 2
4 5 9
4 6 8
0 0


Output

5
0
7
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main{

	int[][] e;
	int[][] dist;
	
	int INF = 1<<29;
	
	void run(){
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			e = new int[n][n];
			//0: can use 1:tochuu 2:cant use
			dist = new int[n][3];
			for(int[]ee:e)Arrays.fill(ee, INF);
			for(int[]d:dist)Arrays.fill(d, INF);
			while(m--!=0){
				int s = sc.nextInt()-1, t = sc.nextInt()-1, c = sc.nextInt();
				e[s][t] = e[t][s] = Math.min(e[s][t], c);
			}
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(n, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return dist[o1[0]][o1[1]] - dist[o2[0]][o2[1]];
				}
			});
			dist[0][0] = 0;
//			debug(e); debug(dist);
			q.add(new int[]{0, 0});
			int res = INF;
			while(!q.isEmpty()){
				int[] V = q.poll();
				int p = V[0], s = V[1];
				if(p==n-1&&s!=1){
					res = Math.min(res, dist[p][s]);
				}
				if(s==0){
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s] + e[p][nx];
						if(w < dist[nx][0]){
							dist[nx][0] = w; q.add(new int[]{nx, 0});
						}
						w = dist[p][s];
						if(w < dist[nx][1]){
							dist[nx][1] = w; q.add(new int[]{nx, 1});
						}
					}
				}
				else if(s==1){
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s];
						if(w < dist[nx][2]){
							dist[nx][2] = w; q.add(new int[]{nx, 2});
						}
					}
				}
				else{
					for(int nx=0;nx<n;nx++){
						if(e[p][nx]==INF)continue;
						int w = dist[p][s] + e[p][nx];
						if(w < dist[nx][2]){
							dist[nx][2] = w; q.add(new int[]{nx, 2});
						}
					}
				}
			}
			System.out.println(res);
		}
	}
	
//	void debug(Object...o){
//		System.out.println(Arrays.deepToString(o));
//	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}