#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector deg(n); vector > edges(n); REP (i, m) { int g, r; cin >> g >> r; --g; REP (j, r) { int h; cin >> h; --h; edges[h].push_back(g); deg[g]++; } } queue q; REP (i, n) if (deg[i] == 0) q.push(i); int ret = 0; while (!q.empty()) { int v = q.front(); q.pop(); ++ret; for (int w: edges[v]) if (!--deg[w]) q.push(w); } cout << ret << endl; return 0; }