// #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair P; typedef pairIP; typedef vector V; typedef vector V2; typedef vector > G; void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));} void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);} #define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++) #define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++) #define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--) #define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--) template void chmax(T &a, const T &b){if(a < b){a = b;}} template void chmin(T &a, const T &b){if(a > b){a = b;}} const ll INF = 1145141919; const ll MOD = 1000000007; const ll NUM = 101010; vectorpath[555]; vectorrev[555]; ll cnt[555]; int main(){ ll N, M; cin >> N >> M; rep(i, M){ ll g, r; cin >> g >> r; rep(j, r){ ll h; cin >> h; path[g].push_back(h); rev[h].push_back(g); } } ll ans = 0; priority_queue, greater

>Q; rep1(i, N){ cnt[i] = path[i].size(); Q.push(P(cnt[i], i)); } while(!Q.empty()){ ll sz = Q.top().first; ll idx = Q.top().second; Q.pop(); if(sz)break; if(cnt[idx] < 0)continue; cnt[idx] = -1; ans++; for(auto from : rev[idx]){ cnt[from]--; Q.push(P(cnt[from], from)); } } cout << ans << endl; return 0; }