#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int pre[100005];
int find(int x){
int r = x;
while(pre[r]!=r){
r = pre[r];
}
int i=x, j;
while(i!=r){
j = pre[i];
pre[i] = r;
i = j;
}
return r;
}
//void mix(int x, int y){
// int fx = find(x);
// int fy = find(y);
// if(fx!=fy){
// pre[fy] = fx;
// }
//}
int main(){
int n;
cin>>n;
int res = n;
for(int i=1; i<=n; i++){
pre[i] = i;
}
for(int i=1; i<=n; i++){
int num;
while(cin>>num){
if(num==0){
break;
}
int f1 = find(i);
int f2 = find(num);
if(f1!=f2){
pre[f2] = f1;
res--;
}
}
}
cout<<res<<endl;
return 0;
}