//由题意可知,这道题就是图中寻找有几个环
//这题想过的话,其实下面两行代码足以
//#include<stdio.h>
//main(){puts("6");}
//运用类似并查集的思想
#include<stdio.h>
using namespace std;
int* root;
int find(int i){
if(i != root[i]) root[i] = find(root[i]);
return root[i];
}
int main(){
int n, a, b, count = 0;
scanf("%d", &n);
root = new int[n + 1];
for(int i = 1; i <= n; i++) root[i] = 0;
for(int i = 1; i <= n; i++){
scanf("%d%d", &a, &b);
if(root[a] == 0 && root[b] == 0) root[a] = a, root[b] = a;
else if(root[a] == 0 && root[b] != 0) root[a] = find(b);
else if(root[a] != 0 && root[b] == 0) root[b] = find(root[a]);
else root[find(a)] = root[find(b)];
}
for(int i=1; i <= n; i++)
if(i == root[i]) count++;
printf("%d\n", count);
return 0;
}
//presented by 大吉大利,今晚AC