#include using namespace std; typedef pair pii; typedef pair > piii; typedef long long ll; const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f; ll res; int n, m, cnt, w[N]; int t[N]; bool st[N]; int main() { cin >> n >> m; for (int i = 2; i < n + 1; i++) t[i] = INF; res = 1; vector > > e(n + 10); priority_queue, greater > q; for (int i = 1; i < m + 1; i++) { int p, x, y; scanf("%d%d%d", &p, &x, &y); if (p > min(t[x], t[y])) { if (t[x] > t[y]) swap(x, y); if (t[x] < p && t[y] > p) { res += t[y] == INF; t[y] = p; q.push({t[y], y}); while (q.size()) { auto u = q.top().second; q.pop(); while (e[u].size() && e[u].begin()->first > t[u]) { auto v = *e[u].begin(); e[u].erase(v); e[v.second].erase({v.first, u}); if (t[v.second] < v.first) continue; assert(t[v.second] > t[u]); res += t[v.second] == INF; t[v.second] = v.first; q.push({v.first, v.second}); } } } else e[x].insert({p, y}), e[y].insert({p, x}); } else e[x].insert({p, y}), e[y].insert({p, x}); printf("%lld\n", res); } return 0; }