#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

void Main(){
    int N; cin >> N;
    VVI edge(400400);
    REP(i,N){
        int a,b; cin >> a >> b; a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int ans = 0;
    vector<bool> vis(400400,false);
    REP(i,400400){
        if(vis[i]) continue;
        stack<Pair> s({Pair(i,0)});
        int nv = 0, ne = 0;
        while(!s.empty()){
            auto [v,ptr] = s.top(); s.pop();
            if(!vis[v]){
                vis[v] = true;
                nv++;
            }
            for(int j=ptr; j<(int)edge[v].size(); j++){
                ne++;
                if(vis[edge[v][j]]) continue;
                s.emplace(v,j+1);
                s.emplace(edge[v][j],0);
                break;
            }
        }

        ne /= 2;
        if(nv == ne+1) ans += nv-1;
        else ans += nv;
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

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

	constexpr int N = 400000;

	int n;
	cin >> n;

	vector<int> a(n), b(n);
	vector<vector<int>> g(N);
	vector<int> cnt(N);
	vector<bool> used(n), visited(N);

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

	queue<int> q;
	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (cnt[i] == 1 && !visited[i]) {
			for (int x : g[i]) {
				if (!used[x]) {
					used[x] = true;
					cnt[a[x] ^ b[x] ^ i]--;
				}
			}
			ans += 1;
			cnt[i] -= 1;
			visited[i] = true;
			q.push(i);
		}
	}

	while (!q.empty()) {
		int x = q.front();
		q.pop();

		for (int i : g[x]) {
			int to = a[i] ^ b[i] ^ x;
			if (cnt[to] == 1 && !visited[to]) {
				for (int u : g[to]) {
					if (!used[u]) {
						used[u] = true;
						cnt[a[u] ^ b[u] ^ to]--;
					}
				}
				ans += 1;
				cnt[to] -= 1;
				visited[to] = true;
				q.push(to);
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans += !visited[i] && cnt[i] > 0;
	}
	cout << ans << '\n';
	return 0;
}