#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define fr first
#define sc second
using namespace std;
#define INF 10000000
typedef pair<int,int> iiP;
typedef pair<int,iiP> P;
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
int n,m;
int S,G;
int min_cost[101][2];
bool used[101][2];
vector< vector<edge> > info;
int solve();
int main(){

  while(cin >> n >> m && (n||m)){
    for(int i=0;i<=n;i++){
      for(int j=0;j<2;j++){
        used[i][j] = false;
        min_cost[i][j] = INF;
      }
    }
    info.resize(n + 1);
    for(int i=0,a,b,c;i<m;i++){
      cin >> a >> b >> c;
      info[a].push_back(edge(b,c));
      info[b].push_back(edge(a,c));
    }
    cout << solve() << endl;

    for(int i=0;i<=n;i++) info[i].clear();
  }
}
int solve(){
  min_cost[1][0] = 0;
  priority_queue< P,vector<P>,greater<P> > que;

  que.push(P(0,iiP(1,0)));

  while(!que.empty()){
    P p = que.top();
    int cost = p.fr,now = p.sc.fr,KIPPU = p.sc.sc;
    que.pop();

    if( now == n ) return cost;

    if( used[now][KIPPU] ) continue;
    used[now][KIPPU] = true;

    for(int i = 0,l = info[now].size();i < l;i++){
      edge e = info[now][i];
      if(cost + e.cost < min_cost[e.to][KIPPU]){
        min_cost[e.to][KIPPU] = cost + e.cost;
        que.push(P(min_cost[e.to][KIPPU],iiP(e.to,KIPPU)));
      }
      if(KIPPU == 0){
        for(int j=0,ll=info[e.to].size();j < ll;j++){
          edge ee = info[e.to][j];
          if(cost < min_cost[ee.to][1]){
            min_cost[ee.to][1] = cost;
            que.push(P(min_cost[ee.to][1],iiP(ee.to,1)));
          }
        }
      }
    }
  }
}