#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < int(n); i++) using namespace std; long long MOD = 998244353; long long INF = 1000000000000000; //10^15 typedef long long ll; typedef unsigned long long ull; ll powMod(ll x, ll n, ll mod) { if (n == 0) return 1; ll t = powMod(x, n/2, mod); t = t * t % mod; if (n & 1) return t * x % mod; return t; } int main(void) { int n, m, g, r, x; vector h[550]; cin >> n >> m; rep(i, m) { cin >> g >> r; rep(j, r) { cin >> x; h[g-1].push_back(x-1); } } bool ch[550] = {}; rep(i, n) { if (h[i].empty()) ch[i] = true; } bool rp = true, f; while (rp) { rp = false; rep(i, n) { f = true; if (h[i].empty()) continue; rep(j, h[i].size()) { if (!ch[h[i][j]]) f = false; if (!f) break; } if (f) { ch[i] = true; h[i].clear(); rp = true; } } } int ans = 0; rep(i, n) if (ch[i]) ans++; cout << ans << endl; return 0; }