#include <bits/stdc++.h>
using namespace std;
int a[205][205], n, v;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
while (cin >> v)
{
if (v == 0)
break;
a[i][v] = 1;
}
}
// floyd
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
a[i][j] = a[i][j] || (a[i][k] && a[k][j]);
int p[205] = {}; // 记录第i个人是否需要别人给
for (int i = 1; i <= n; i++)
p[i] = i;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i][j] == 1)
p[j] = p[i];
int ans = 0;
for (int i = 1; i <= n; i++)
if (p[i] == i)
ans++;
cout << ans;
return 0;
}