#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< >(b,vector(c,d)) #define vvv(a,b,c,d,e) vector > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair; using vi = vector; using vll = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int N, M; while (cin >> N >> M) { vector > G(N); queue Q; rep(a, M) { int g, r; cin >> g >> r; g--; rep(b, r) { int h; cin >> h; --h; G[g].insert(h); } } rep(a, N)if (!sz(G[a]))Q.push(a); int re = 0; while (sz(Q)) { re++; int p = Q.front(); Q.pop(); rep(a, N)if (G[a].count(p)) { if (sz(G[a]) == 1) { Q.push(a); } G[a].erase(p); } } cout << re << endl; } }