#include using namespace std; using int64 = long long; using uint64 = unsigned long long; const int MAX_N = 500; vector G[MAX_N]; int n, m, indeg[MAX_N]; int solve() { int res = 0; queue Q; for (int i = 0; i < n; i++) { if (indeg[i] == 0) { Q.push(i); res++; } } while (!Q.empty()) { int u = Q.front(); Q.pop(); for (int to : G[u]) { if (indeg[to] > 0) { indeg[to]--; if (indeg[to] == 0) { Q.push(to); res++; } } } } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < m; i++) { int g, r; cin >> g >> r; g--; for (int j = 0; j < r; j++) { int h; cin >> h; h--; G[h].push_back(g); indeg[g]++; } } cout << solve() << endl; return 0; }