#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn=105;
int n,m;
struct edge
{
int from,to,w;
};
struct node
{
int id,dis;
bool operator<(const node &a) const
{
return dis>a.dis;
}
};
vector<edge>e[maxn];
void dijkstra()
{
int s=1;
node t,u;
priority_queue<node>q;
int dis[maxn];
bool done[maxn];
for(int i=1;i<=n;i++)
{
dis[i]=9999999;
done[i]=false;
}
dis[s]=0;
t.id=s;
t.dis=dis[s];
q.push(t);
while(!q.empty())
{
u=q.top();
q.pop();
if(done[u.id]) continue;
done[u.id]=true;
for(int i=0;i<e[u.id].size();i++)
{
edge y=e[u.id][i];
if(done[y.to]) continue;
if(dis[y.to]>y.w+u.dis)
{
dis[y.to]=y.w+u.dis;
t.id=y.to;
t.dis=dis[y.to];
q.push(t);
}
}
}
cout<<dis[n]<<endl;
}
int main()
{
while(cin>>n>>m)
{
if(n==0&&m==0) break;
int i,j;
int a,b,c;
edge t;
for(i=1;i<=n;i++)
{
e[i].clear();
}
for(i=0;i<m;i++)
{
cin>>a>>b>>c;
t.from=a;
t.to=b;
t.w=c;
e[a].push_back(t);
t.from=b;
t.to=a;
e[b].push_back(t);
}
dijkstra();
}
return 0;
}