#include <iostream>
#include <set>
using namespace std;
const int N = 1e6+10;
int p[N];
int find(int x){
    if(x != p[x]) p[x] = find(p[x]);
    return p[x];
}
int main(){
    int a, b;
    set<int> s, cnt;
   for(int i = 1; i <= N; i ++) p[i] = i;
    while(cin>>a>>b){
        p[find(a)] = find(b);
        cnt.insert(a);
        cnt.insert(b);
    } 
    for(auto i : cnt){
        s.insert(find(i));
    }
    cout<<s.size();
    return 0;
}