#include using namespace std; #define rep(i, j, n) for(int i=j;i pi; template using vt = vector; template using vvt = vector>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {0, -1, 0, 1, 1, 1, -1, -1}; int dy[] = {-1, 0, 1, 0, 1, -1, 1, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vvt edge(n); vt r(n), cou(n, 0); rep(i, 0, m) { int g; cin >> g; g--; cin >> r[g]; rep(i, 0, r[g]) { int x; cin >> x; x--; edge[x].push_back(g); } } int ans = 0; queue que; rep(i, 0, n) { if(r[i] == cou[i]) que.push(i); } while(!que.empty()) { int cu = que.front(); que.pop(); ans++; for(auto to : edge[cu]) { cou[to]++; if(r[to] == cou[to]) que.push(to); } } cout << ans << endl; }