#include<iostream>
using namespace std;
int main(){
int student[100000][3];
int n,i,j,count;
while(cin>>n){
for(i=0;i<n;i++)
{
student[i][0]=i;
cin>>student[i][1];
student[i][2]=0;
}
student[0][2]=1;
count=1;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if((student[i][0]==student[j][0]||student[i][0]==student[j][1]||student[i][1]==student[j][0]||student[i][1]==student[j][1])&&student[j][2]!=0)
{
student[i][2]=student[j][2];
break;
}
}
if(student[i][2]==0)
{
count++;
student[i][2]=count;
}
for(j=i+1;j<n;j++)
{
if(student[j][2]!=0)
{
continue;
}
else if(student[i][0]==student[j][0]||student[i][0]==student[j][1]||student[i][1]==student[j][0]||student[i][1]==student[j][1])
{
student[j][2]=student[i][2];
}
}
}
cout<<count<<endl;
}
}