#include <bits/stdc++.h>
#define ll long long
#define p pair<ll, int>
using namespace std;

int inf[20005];
int main() {
    int n, m;
    while (cin >> n >> m, n | m) {
        memset(inf, 0, sizeof(inf));
        inf[1] = 1;
        vector<p> v;
        int s[m], d[m];
        for (int i = 0; i < m; i++) {
            ll t;
            cin >> t >> s[i] >> d[i];
            v.push_back(p(t, i));
        }
        sort(v.begin(), v.end());
        for (int i = 0; i < m; i++) {
            int idx = v[i].second;
            if (inf[s[idx]]) inf[d[idx]] = 1;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (inf[i]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}
