// Author Nagendra patel
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define MOD 1000000007 
#define INT_BITS 16
#define INF 1e18  
#define pi 3.141592
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n" 
#define pb push_back
#define pii pair<int,,int>
#define MAXN   1001
#define all(x) (x).begin(), (x).end()

#ifndef ONLINE_JUDGE
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';}
#define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}}
#else
#define deb(x) ;
#define debug(x,y) ;
#define deb_arr(a,n) ;
#define deb_mat(dist,n,m) ;
#endif

#define x first
#define y second
#define N 400003




vector<int> G[N]; 

int cnt,cnt2,vis[N];

void dfs(int i) {
    vis[i]=1;
    ++cnt;
    for(int nx:G[i]) {
        if(!vis[nx])
            dfs(nx);
        ++cnt2;
    }
}

int32_t main() 
{
    fast;

    int n; 
    cin>>n;
    while(n--) 
    {
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
     int ans=0;
    for(int i=1;i<N;++i) {
        cnt=cnt2=0;
        if(!vis[i])
            dfs(i);
        ans+=min(cnt,cnt2/2);
    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define vec vector
using namespace std;
 
const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;
 
long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}
 
ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
   //cin >> q;
  while (q-- >0) {
    int n;
    cin >> n;
    int m = 400000;
    vec<vec<int>> gr(m);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      gr[x].push_back(y);
      gr[y].push_back(x);
    }
    vec<bool> was(m);
    function<void(int, vec<int>&)> dfs = [&] (int v, vec<int>& comp) {
      was[v] = true;
      comp.push_back(v);
      for (int next : gr[v]) {
        if (!was[next]) {
          dfs(next, comp);
        }
      }
    };
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      if (was[i]) continue;
      vec<int> comp;
      dfs(i, comp);
      int deg = 0;
      for (int x : comp) {
        deg += gr[x].size();
      }
      int edges = deg / 2;
      if (edges < comp.size()) {
        assert (edges + 1 == comp.size());
        ans += edges;
      } else {
        ans += comp.size();
      }
    }
    cout << ans << "\n";
  }

 
  return 0;
}
