#include #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { cin.tie(nullptr) -> sync_with_stdio(false); int n, m; cin >> n >> m; vector cnt(n); vector has(n); vector> to(n); while (m--) { int g, r; cin >> g >> r; --g; has[g] = true; cnt[g] = r; while (r--) { int h; cin >> h; --h; to[h].push_back(g); } } int ans = 0; queue q; rep(i, n) if (!has[i]) { q.push(i); ans++; } while (q.size()) { int v = q.front(); q.pop(); for (int u : to[v]) { if (--cnt[u] == 0) { q.push(u); ans++; } } } cout << ans << '\n'; return 0; }