#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9)
#define LINF ll(1e18)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>

int n;
vector<int> to[410000];
int visited[410000];
int cnt;
bool tree;

void dfs(int v, int u=-1){
  if(visited[v]!=0){
    tree=0; return;
  }
  cnt++;
  visited[v]=1;
  for(auto x : to[v]){
    if(x==u) continue;
    dfs(x,v);
  }
  return;
}

int main(){
  cin>>n;
  rep(i,n){
    int a,b; cin>>a>>b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int ans=0;
  rep(i,410000){
    if(visited[i]!=0) continue;
    tree=1;
    cnt=0;
    dfs(i);
    if(tree) ans+=cnt-1;
    else ans+=cnt;
  }
  cout<<ans<<endl;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 4e5+10;
int f[N],s[N];
int ff(int x){return f[x]?f[x]=ff(f[x]):x;}
int main(){
    int n;
    cin>>n;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        int a,b;
        cin>>a>>b;
        int u = ff(a), v = ff(b);
        if(u!=v &&(!s[u]||!s[v]))
                f[u] = v,s[v]|=s[u],ans++;
        else if(!s[u])s[u]=1,ans++;
    }
    cout<<ans<<endl;
}
