#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int ind[99999];
int oud[99999];
vector<int> a[99999];
bool o[99999];
int n;
int maxx = -1;
void topo() {
queue<int> q;
for(int i = 1; i <= maxx; i++){
if(ind[i] == 0){
q.push(i);
}
}
while(!q.empty()){
int ls = q.front();
q.pop();
o[ls] = 1;
for(int i = 0; i < a[ls].size(); i++){
int np = a[ls][i];
if(--ind[np] == 0){
q.push(np);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++){
int e, u, v;
cin >> e;
maxx = max(maxx,e);
cin >> u;
for(int j = 1; j <= u; j++){
cin >> v;
a[e].push_back(v);
ind[v]++;
oud[e]++;
}
}
topo();
int sum = 0;
for(int i = 1; i <= n; i++){
if(o[i] == 0){
sum++;
}
}
if(sum == 0){
cout << "YES";
}else{
cout << sum;
}
return 0;
}