#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define clr(x, k) memset((x), (k), sizeof(x))
#define MAXe 10002 //e;
#define MAXn 210
#define INF 1<<30
using namespace std;
struct Edge
{
int to, w, next;
}e[MAXe<<1];
int head[MAXn], dist[MAXn], inq[MAXn];
int n, m, T, st, en;
queue<int> q;
void add_e(int u, int v, int w)
{
e[T].to = v;
e[T].w = w;
e[T].next = head[u];
head[u] = T++;
return ;
}
void spfa(int st)
{
for (int i=1;i<=n;i++)
{
dist[i] = (i==st)?0:INF;
}
clr(inq,0);
q.push(st);
while (!q.empty())
{
int u = q.front(); q.pop();
inq[u] = 0;
for (int i=head[u];i!=-1;i=e[i].next)
{
int v = e[i].to;
if (dist[v] > dist[u] + e[i].w)
{
dist[v] = dist[u] + e[i].w;
if (!inq[v])
{
q.push(v);
inq[v] = 1;
}
}
}
inq[u] = 0;
}
}
int main()
{
while (scanf("%d %d", &n, &m), n||m)
{
clr(head,-1);
int u, v, w;
T = 0;
for (int i=0;i<m;i++)
{
scanf("%d %d %d", &u, &v, &w);
add_e(u,v,w);
add_e(v,u,w);
}
spfa(1);
printf("%d\n", dist[n]);
}
return 0;
}