#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,n) for(int i = 0;i<((int)(n));i++) #define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--) #define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--) typedef long long ll; typedef pair mp; ll mod = 1e9+7; //LLONG_MIN //WA int main(void){ ll n,m,g,r,h,get[510]={},ans=0; cin>>n>>m; vector need[510]; vector go[510]; rep(i,m){ cin>>g>>r; rep(j,r){ cin>>h; need[g].push_back(h); go[h].push_back(g); } } queue Q; while(1){ bool change=false; reg(i,1,n){ if(get[i]==0){ bool can=true; rep(j,need[i].size())if(get[need[i][j]]==0){ can=false; break; } if(can){ get[i]=1; change=true; } } } if(!change)break; } reg(i,1,n)if(get[i]!=0)ans++; cout<