#include "bits/stdc++.h" using namespace std; using ll = long long; using ull = unsigned long long; typedef pair< long long, long long > P; typedef pair< long long, P > PP; typedef pair< P, P > PPP; const long long MOD = 1e9 + 7; const long long INF = 5e18; const double DINF = 5e14; const double eps = 1e-10; const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 }; #define fr first #define sc second #define pb push_back #define eb emplace_back #define ALL(x) (x).begin(),(x).end() int n, m, h, g, r, ans, rr[510]; map>mp; bool b[510]; int main() { cin >> n >> m; for (int i = 0;i < m;i++) { cin >> g >> r; rr[g] = r; for (int j = 0;j < r;j++) { cin >> h; mp[g].eb(h); } } while (true) { bool fl = 0; for (int i = 1;i <= n;i++) { if (b[i])continue; if (mp[i].size() == 0) { ans++; b[i] = 1; fl = 1; } else { bool f = 0; for (int j = 0;j < rr[i];j++) { if (!b[mp[i][j]]) { f = 1; break; } } if (!f) { ans++; b[i] = 1; fl = 1; } } } if (!fl) { cout << ans << endl; return 0; } } return 0; }