#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vvi dist(n,vi(n,INFTY));
		rep(i,m){
			int s,d,w; cin>>s>>d>>w;
			s--; d--;
			dist[s][d]=dist[d][s]=w;
		}
		
		vvi dp(3,vi(n,INFTY)),vis(3,vi(n));
		dp[0][0]=0;
		for(;;){
			int cc=-1,ci=-1;
			rep(c,3) rep(i,n){
				if(vis[c][i])
					continue;
				if(cc==-1 || dp[c][i]<dp[cc][ci]){
					cc=c;
					ci=i;
				}
			}
			if(cc==-1 || dp[cc][ci]==INFTY)
				break;
			vis[cc][ci]=1;
			
			if(cc==0 || cc==1){
				rep(i,n) if(dist[ci][i]!=INFTY)
					dp[cc+1][i]=min(dp[cc+1][i],dp[cc][ci]);
			}
			if(cc==0 || cc==2){
				rep(i,n)
					dp[cc][i]=min(dp[cc][i],dp[cc][ci]+dist[ci][i]);
			}
		}
		
		cout<<min(dp[0][n-1],dp[2][n-1])<<endl;
	}
	
	return 0;
}