// Problem: 
// 			B - Reversible Cards
// 			
// 		
// Contest: AtCoder - AtCoder Regular Contest 111
// URL: https://atcoder.jp/contests/arc111/tasks/arc111_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)	

const int N = 4e5+7,M = 2 * N;
vector<int> E[N];
int st[N],in_stk[N],cir;

void dfs(int u,int fa)
{
	in_stk[u] = 1;
	st[u] = 1;
	for(auto& v : E[u])
	{
		if(v == fa)	continue;
		if(in_stk[v])	cir = 1;
		if(st[v])	continue;
		dfs(v,u);
	}
	in_stk[u] = 0;
}

int main()
{
	int n;scanf("%d",&n);
	set<int> col;
	forn(i,1,n)
	{
		int u,v;scanf("%d%d",&u,&v);
		E[u].push_back(v);E[v].push_back(u);
		col.insert(u);col.insert(v);
	}

	int res = col.size();
	// cout << res << endl;
	for(auto& i : col)
		if(!st[i])
		{
			cir = 0;
			dfs(i,-1);
			if(!cir)	--res;
		}
	printf("%d",res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> using lqueue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using gqueue = priority_queue<T, vector<T>, less<T>>;

constexpr int max_v = 400000;

array<vec<int>, max_v + 1> g;
array<bool, max_v + 1> vis;

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;
    for (int i = 0; i <= max_v; ++i) {
        if (vis[i]) continue;
        vis[i] = true;

        int sum = 0, cnt = 0;
        queue<int> que;
        que.push(i);
        while (!que.empty()) {
            int c = que.front(); que.pop();
            sum += g[c].size(); ++cnt;
            for (auto v : g[c]) {
                if (vis[v]) continue;
                vis[v] = true;
                que.push(v);
            }
        }

        sum /= 2;
        if (cnt <= sum) {
            ans += cnt;
        }
        else {
            ans += cnt - 1;
        }
    }

    cout << ans << endl;
}

