#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;
const int MAXM = 4e5 + 5;

int p[MAXN][2];
bool del[MAXN];

vector<int> poss[MAXM];
int cnt[MAXM];
inline int get_pos(vector<int> &vec)
{
	for(int i=0; i<(int)vec.size(); ++i)
		if(!del[vec[i]]) return vec[i];
	return -1;
}

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		scanf("%d%d",&p[i][0],&p[i][1]);
	
	for(int i=1; i<=n; ++i)
		for(int j=0; j<=1; ++j)
			++cnt[p[i][j]], poss[p[i][j]].push_back(i);
	
	queue<int> q;
	for(int i=1; i<MAXM; ++i)
		if(cnt[i] == 1) q.push(i);
	
	int ans = 0;
	while(q.size())
	{
		int u = q.front(); q.pop();
		int pos = get_pos(poss[u]);
		if(pos == -1) continue;
		++ans; del[pos] = 1;
		
		int v = p[pos][0] + p[pos][1] - u;
		if(--cnt[v] == 1) q.push(v);
	}
	
	set<int> t;
	for(int i=1; i<=n; ++i)
		if(!del[i]) t.insert(p[i][0]), t.insert(p[i][1]);
	printf("%d",ans + (int)t.size());
	return 0;
}
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<int,int,int> TUP;
using P = pair<int,int>;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

int parent[514514];
int connectSize[514514];
int connectEdge[514514];

void dsu(){
    for(int i = 0;i<514514;i++) parent[i] = i,connectSize[i] = 1 , connectEdge[i] = 0;
}
int searchRoot(int V){
    //頂点Vの親==頂点Vということは頂点Vはその木の根である。
    if(parent[V] == V){
        return V;
    }
    else{
        //一回ごとにparent[V]を更新する。辺の縮約
        return parent[V] = searchRoot(parent[V]);
    }
}
bool same(int X,int Y){
    if(searchRoot(X) == searchRoot(Y)) return true;
    else return false;
}
void unite(int X,int Y){
    //X,Yの高さが高い方の木の「高さ0の根」に高さが低い方の根を付ける
    int Xroot = searchRoot(X); int Yroot = searchRoot(Y);
    if(connectSize[Xroot] > connectSize[Yroot]) swap(Xroot,Yroot);
    //同じ根を持つ木を併合することはしなくてよい
    if(Xroot == Yroot){
        connectEdge[Yroot]++;
        connectEdge[Xroot] = connectEdge[Yroot];
        return;
    }
    //Xrootがサイズが小さい方にする→XrootをYroot側にくっつける
    
    parent[Xroot] = Yroot;
    connectEdge[Yroot]++;
    connectSize[Yroot] += connectSize[Xroot];
    connectSize[Xroot] = connectSize[Yroot];
    connectEdge[Yroot] += connectEdge[Xroot];
    connectEdge[Xroot] = connectEdge[Yroot];
}


int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N;cin >> N;
    dsu();
    vector<int> loopmyself(400005);
    for(int i = 0;i<N;i++){
        int a,b;cin >> a >> b;a--;b--;
        if(a > b) swap(a,b);
        unite(a,b);
    }
    int ans = 0;
    vector<bool> already(400005);
    int edgecnt = 0;
    for(int i = 0;i<400005;i++){
        if(searchRoot(i) != i) continue;
        if(connectEdge[searchRoot(i)] >= connectSize[searchRoot(i)]){
            ans += connectSize[searchRoot(i)];
        }
        else{
            ans += connectSize[searchRoot(i)] - 1;
        }
    }
    cout << ans << endl;
}