#include<bits/stdc++.h>
using namespace std;
vector<int>e[1005] ;
queue<int>q ;
int n,m,ind[1005],x,y,o,flag=0,ans=0 ;
int main(){
cin >> n >> m ;
for(int i = 1 ; i <= m ; i++){
cin >> x >> o ;
for(int j = 1 ; j <= o ; j++){
cin >> y ;
ind[y]++ ;
e[x].push_back(y);//输入
}
}
for(int i = 1; i <= n; i++)if(ind[i] == 0)q.push(i);//记录ind为0的点
while(!q.empty()){
ans++ ;//记数
int u = q.front();
q.pop();
for(int i = 0; i < e[u].size(); i++){
int v = e[u][i];
ind[v]--;
if(ind[v] == 0)q.push(v);//拆掉
}
}
if(ans==n)cout<<"YES";
else cout << n-ans;
return 0;
}