#include<bits/stdc++.h>
using namespace std;
vector<int> G[400400];
bool vis[400400];
int ce,cv;
void dfs(int x)
{
  vis[x]=true;
  cv++;
  ce+=(int)(G[x].size());
  for(int i=0;i<(int)(G[x].size());i++)
    if(!vis[G[x][i]])
      dfs(G[x][i]);
  return ;
}
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans=0;
  for(int i=0;i<400000;i++)
    if(!vis[i])
  {
    ce=cv=0;
    dfs(i);
      ce/=2;
      ans+=min(ce,cv);
    }
  cout<<ans<<endl;
  return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;

int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};
class DisjointSet{
    public:
        vector<ll> rank,p,siz,es;

        DisjointSet(){}
        DisjointSet(ll size){
            rank.resize(size,0);
            p.resize(size,0);
            siz.resize(size,1);
            es.resize(size,0);
            rep(i,size) makeSet(i);
        }

        void makeSet(ll x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(ll x, ll y){
            return root(x) == root(y);
        }

    
        void unite(ll x, ll y){
            x = root(x);
            y = root(y);
            es[x]++;
            if(x == y) return;
            if(rank[x] > rank[y]){
                siz[x] += siz[y];
                es[x] += es[y];
                p[y] = x;
            }
            else{
                siz[y] += siz[x];
                es[y] += es[x];
                p[x] = y;
                if(rank[x] == rank[y]) rank[y]++;
            } 
        }
        ll root(ll x){
            if(x != p[x]){
                p[x] = root(p[x]);
            }
            return p[x];
        }

        ll size(ll x){
            return siz[root(x)];
        }

        ll esize(ll x){
            return es[root(x)];
        }

};


int main(){
    int n; cin >> n;
    DisjointSet uf(400000);

    rep(i,n){
        int a,b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,400001){
        if(uf.root(i) == i) ans += min(uf.size(i),uf.esize(i));
    }
    cout << ans << endl;
}


