#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ int n, m; cin >> n >> m; vector> g(n); vector redge(n,0); rep(i,m) { int a, r; cin >> a >> r; a--; redge[a] = r; rep(j,r) { int h; cin >> h; h--; g[h].emplace_back(a); } } vector cnt(n,0); queue que; for (int i = 0; i < n; i++) if (cnt[i] == redge[i]) que.push(i); int res = 0; while (!que.empty()) { int u = que.front(); que.pop(); res++; for (auto v : g[u]) { cnt[v]++; if (cnt[v] == redge[v]) que.push(v); } } cout << res << endl; return 0; }