调不出来qwq
#include <bits/stdc++.h>
using namespace std;
int n, a[610], b[610], ind[610], cnt;
vector<int> p[610];
void topo(){
queue<int> q;
for(int i = 1 ; i <= n ; i ++){
if(!ind[a[i]]){
q.push(a[i]);
}
}
while(!q.empty()){
int x = q.front();
q.pop();
if(!b[x]) continue;
for(int i = 0 ; i < p[x].size() ; i ++){
ind[p[x][i]] --;
if(!ind[p[x][i]]){
q.push(p[x][i]);
}
}
cnt ++;
}
}
int main(){
cin >> n;
for(int i = 1 ; i <= n ; i ++){
int x, t;
cin >> x >> t;
a[i] = x;
b[x] = i;
for(int j = 1 ; j <= t ; j ++){
int tmp;
cin >> tmp;
p[i].push_back(tmp);
ind[tmp] ++;
}
}
topo();
if(cnt == n){
cout << "YES" << endl;
}
else{
cout << n - cnt << endl;
}
return 0;
}