#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

/*** UnionFind????????? ***/
class UnionFind {
private:
    //uni[i]<0????????°i?????????????????§???????????°find(uni[i])??????
    vector<int> uni;
    //??°???????????°
    int SIZE;
public:

    UnionFind(int size) {
        //????????¶?????§?????¨?????????-1????¨???????????????£??????????????????
        this->uni.resize(size, -1);
        this->SIZE = size;
    }
     UnionFind() {}
     void resize(int size) {
         this->uni.resize(size, -1);
         this->SIZE = size;
     }

    //x???????????????
    int find(int x) {
        //uni[x]<0????????§x??????
        if (uni[x] < 0) return x;
        //uni[x]????????????????????\???????????¨??§??£?¶???§?????¢?´¢???????????????
        return uni[x] = find(uni[x]);
    }

    //x??¨y???????????°?????????????????°true
    bool same(int x, int y) {
        //x??¨y???????????????????????°????????°?????????????±?????????¨?????????
        return find(x) == find(y);
    }

    //x??¨y????????????????±?????????°??????????????????
    //????????????????????£???????????°true?????????
    //x??¨y????????¨?????¨????????°?????????????????°false?????????
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        //??¨?????±???????°????????????????????????§??????????????????????????????
        if (uni[x] > uni[y]) swap(x, y);
        //y?????°????????????x????¶????
        uni[x] += uni[y];
        //y?????????x??¨??????
        uni[y] = x;
        this->SIZE--;
        return true;
    }

    //??°???????????°?????????
    int size() {
        return this->SIZE;
    }

    //x????±?????????°???????????????????????°?????????
    int size(int x) {
        return -uni[find(x)];
    }
};

using type = tuple<int, int, int>;
void solve(int N, int M) {
    VT<type> vec(M);
    for_each(ALL(vec), [](type &e) {
        int t, s, d;scanf("%d%d%d", &t, &s, &d);
        e = make_tuple(t, s - 1, d - 1);
    });
    SORT(vec);
    UnionFind uf(N);
    FORE(e, vec) {
        int t, s, d;
        tie(t, s, d) = e;
        if (uf.same(0, s)) {
            uf.unite(s, d);
        }
    }
    cout << uf.size(0) << endl;
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n >> m, n) {
        solve(n, m);
        //return 0;
    }
}

Measured memory_bytes: 3444