#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
typedef pair<int, int>p;
int n, m;
struct edgee
{
int to, value;
};
edgee edge[4000020];
int dist[2050],first[2050],nextt[4000020];
long long num[2050];
int edgetot = 1;
bool isinstack[2050];
void addedge(int from, int to, int value)
{
edge[edgetot].to = to;
edge[edgetot].value = value;
nextt[edgetot] = first[from];
first[from] = edgetot;
edgetot++;
edge[edgetot].to = from;
edge[edgetot].value = value;
nextt[edgetot] = first[to];
first[to] = edgetot;
edgetot++;
}
struct com
{
bool operator()(p a, p b)
{
return a.first < b.first;
}
};
long long dfs_num(int numm,int t)
{
if (numm == t)return 1;
if (num[numm] != 0)return num[numm];
long long ans = 0;
for (int i = first[numm]; i; i = nextt[i])
{
int to = edge[i].to;
if (dist[to] < dist[numm])
ans += dfs_num(to, t);
}
return num[numm] = ans;
}
/*void num_bfs(int t)
{
queue<int>que;
num[t] = 1;
isinstack[t] = true;
que.push(t);
while (!que.empty())
{
int now = que.front();
que.pop();
for (int i = first[now]; i; i = nextt[i])
{
int to = edge[i].to;
if (dist[to]>dist[now])
{
num[to] =num[to]+num[now];
if (!isinstack[to])
que.push(to),isinstack[to]=true;
}
}
}
}*/
long long distra(int s, int t)
{
for (int i = 1; i <= n; i++)dist[i] = 1000000000;
dist[t] = 0;
priority_queue<p, vector<p>, com>que;
que.push(p(0, t));
while (!que.empty())
{
p temp = que.top();
int now = temp.second; int value = temp.first;
if (dist[now] < value)continue;
que.pop();
for (int i = first[now]; i; i = nextt[i])
{
int to = edge[i].to;
if (dist[to] > dist[now] + edge[i].value)
{
dist[to] = dist[now] + edge[i].value;
que.push(p(dist[to], to));
}
}
}
//num_bfs(t);
dfs_num(s, t);
return num[s];
}
int main()
{
// for (int i = 31; i >= 2; i--)
// {
// cout << i << " " << i - 1 << " " << 1 << endl;
// cout << i << " " << i - 1 << " " << 1 << endl;
// }
while (scanf("%d", &n) &&n!=0&&scanf("%d",&m))
{
edgetot = 1;
for (int i = 1; i <= n; i++)first[i] = 0, num[i] = 0,isinstack[i]=false;
for (int i = 0; i < m; i++)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
addedge(a, b, c);
}
long long k = distra(1, 2);
printf("%lld\n", k);
}
return 0;
}
/*
bfs是错的是因为如下数据:
1 5 1
5 6 1
5 7 1
5 2 1
6 2 1
7 2 1
如果在bfs的时候5比7,6先出队那麻烦就大了!!!!
*/