#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define INF LONG_MAX
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
typedef pair<PLL,int> State;

struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  int dijkstra(){
    ll dp[V][3];
    rep(i,V){
      rep(j,3) dp[i][j] = INF;
    }
    dp[0][0] = 0;

    // 使用したチケットの枚数,dist,頂点番号
    priority_queue<State,vector<State>, greater<State> > que;

    que.push(State(PII(0,0),0));

    while(!que.empty()){
      State p = que.top(); que.pop();
      ll current_dist = p.first.second, current_node = p.second;
      ll current_thicket = p.first.first;
      if(dp[current_node][current_thicket] < current_dist) continue;
      for(auto e : G[current_node]){
        if(current_thicket == 0){
          // チケットを使わない場合
          if(dp[current_node][current_thicket] + e.cost < dp[e.to][current_thicket]){
            dp[e.to][current_thicket] = dp[current_node][current_thicket] + e.cost;
            que.push(State(PLL(current_thicket,dp[e.to][current_thicket]),e.to));
          }
          // チケットを使い始める
          if(dp[current_node][current_thicket] < dp[e.to][current_thicket + 1]){
            dp[e.to][current_thicket+1] = dp[current_node][current_thicket];
            que.push(State(PLL(current_thicket+1,dp[e.to][current_thicket+1]),e.to));
          }
        }else if(current_thicket == 1){
          // チケットを使い終わる
          if(dp[current_node][current_thicket] < dp[e.to][current_thicket + 1]){
            dp[e.to][current_thicket+1] = dp[current_node][current_thicket];
            que.push(State(PLL(current_thicket+1,dp[e.to][current_thicket+1]),e.to));
          }
        }else{
          // チケットを使わない場合
          if(dp[current_node][current_thicket] + e.cost < dp[e.to][current_thicket]){
            dp[e.to][current_thicket] = dp[current_node][current_thicket] + e.cost;
            que.push(State(PLL(current_thicket,dp[e.to][current_thicket]),e.to));
          }
        }

      }
    }
    return min(dp[V-1][0],dp[V-1][2]);
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  while(true){
    cin >> n >> m;
    if(n==0 && m == 0) break;
    graph g(n);
    rep(i,m){
      ll a,b,c;
      cin >> a >> b >> c;
      a--,b--;
      g.add_edge(a,b,c);
      g.add_edge(b,a,c);
    }
    cout << g.dijkstra() << endl;
  }

  return 0;
}



Measured memory_bytes: 3204