#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
queue <int> q;
vector <int> e[maxn];
int in[maxn];
bool vis[maxn];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
int x, m;
cin >> x >> m;
vis[x] = 1;
for (int j = 1; j <= m; j++)
{
int y;
cin >> y;
e[x].push_back(y);
in[y]++;
}
}
for (int i = 1; i <= n; i++)
{
if (in[i] == 0)
{
q.push(i);
}
}
int ans = 0;
while(!q.empty())
{
ans++;
int x = q.front();
q.pop();
for (auto y : e[x])
{
in[y]--;
if (in[y] == 0 && vis[y])
{
q.push(y);
}
}
}
if (ans == n)
{
cout << "YES" << endl;
}
else
{
cout << n - ans << endl;
}
return 0;
}