#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

vector<Weight> dijkstra(const Graph &g, int s) {
  vector<Weight> dist(g.size(), INF);
  dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return dist;
}
int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    Graph g(n*3);
    REP(i,m) {
      int a, b, c;
      cin >> a >> b >> c;
      a--; b--;
      int a1 = a*3, b1 = b*3;
      int a2 = a1+1, b2 = b1+1;
      int a3 = a2+1, b3 = b2+1;
      g[a1].push_back(Edge(a1,b1,c));
      g[b1].push_back(Edge(b1,a1,c));
      g[a1].push_back(Edge(a1,b2,0));
      g[b1].push_back(Edge(b1,a2,0));
      g[a2].push_back(Edge(a2,b3,0));
      g[b2].push_back(Edge(b2,a3,0));
      g[a3].push_back(Edge(a3,b3,c));
      g[b3].push_back(Edge(b3,a3,c));
    }
    vector<int> dist = dijkstra(g,0);
    int t = (n-1)*3;
    cout << min(dist[t], dist[t+2]) << endl;
  }
}