#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
// #include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> p32;
typedef pair<ll, ll> p64;
typedef pair<p64, p64> pp64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<char>> vvc64;

typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define f first
#define s second

#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
#define pp pair<ll, p64>
#define pc pair<int, char>
ll mpow(ll a, ll b)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2);
    t1 *= t1;
    t1 %= MOD;
    if (b % 2)
        t1 *= a;
    t1 %= MOD;
    return t1;
}
ll mpow(ll a, ll b, ll p)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2, p);
    t1 *= t1;
    t1 %= p;
    if (b % 2)
        t1 *= a;
    t1 %= p;
    return t1;
}

void norm(ll &n)
{
    n %= MOD;
    n += MOD;
    n %= MOD;
}

void dfs(int n, vv64 &adj, v64 &visited, int &count, int &m)
{
    visited[n] = 1;
    count++;
    for (int i = 0; i < sz(adj[n]); i++)
    {
        m++;
        int c = adj[n][i];
        if (visited[c] == 0)
            dfs(c, adj, visited, count, m);
    }
}
void solve(ll t)
{
    int n;
    cin >> n;
    int m = 4e6;
    vv64 adj(m + 1);
    for (int i = 1; i <= n; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    v64 visited(m + 1, 0);
    ll ans = 0;
    for (int i = 1; i <= m; i++)
    {
        if (visited[i] == 0)
        {
            int count = 0, edges = 0;
            dfs(i, adj, visited, count, edges);
            edges /= 2;
            ans += count;
            if (edges < count)
                ans--;
        }
    }
    cout << ans << endl;
}
int main()
{

    fast_cin();
    ll t = 1;
    // cin >> t;
    forn(i, t)
    {
        solve(i + 1);
    }
}
#include<bits/stdc++.h>

using namespace std;

const int maxN = 1e6 + 100;
int N, M, t[maxN], x[maxN], y[maxN], sz[maxN], vol[maxN];

int tata (int nod)
{
    if (t[nod] == nod) return nod;
    return t[nod] = tata (t[nod]);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &M);
for (int i=1; i<=M; i++)
    scanf ("%d %d", &x[i], &y[i]),
    N = max (N, max (x[i], y[i]));
for (int i=1; i<=N; i++)
    t[i] = i, vol[i] = 0, sz[i] = 1;
for (int i=1; i<=M; i++)
{
    int a = tata (x[i]), b = tata (y[i]);
    if (a == b) vol[a] ++;
    else vol[a] += vol[b] + 1, sz[a] += sz[b], t[b] = a;
}
int ans = 0;
for (int i=1; i<=N; i++)
    if (tata (i) == i)
        ans += min (sz[i], vol[i]);
printf ("%d\n", ans);
return 0;
}
