#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define ui unsigned int
    #define ld long double
    #define mod 1000000007LL
    #define eps 1e-13
    // #define PI 3.141592653589793238L
    #define INF 1000000011
    #define INFLL 1000000000000000011LL
    #define vi vector<int>
    #define vll vector<long long>
    #define pii pair<int, int>
    #define pll pair<long long, long long>
    #define pil pair<int, long long>
    #define pli pair<long long, int>
    #define mp make_pair
    #define F first
    #define S second
    #define pb push_back
    #define fo(i,a,n) for(i = (a); i < (n); i++)
    #define gtl(x) getline(cin, (x))
    #define flsh fflush(stdout)
    #define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #define gcd __gcd
    #define all(a) (a).begin(), (a).end()
    #define sz(a) (int)((a).size())
    #define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)
     
    ll modx(ll Base, ll exponent)
    {
    	ll ans = 1;
    	if(Base == 1)
    		return Base;
    	while(exponent)
    	{
    		if(exponent & 1)
    			ans = (ans * Base)%mod;
    		Base = (Base * Base)%mod;
    		exponent = exponent >> 1;
    	}
    	return ans;
    }
     
    ll inmodx(ll num)
    {
    	return (modx(num, mod-2LL));
    }
     
    bool cmp(pii a, pii b)//true for a before b
    {
    	if(a.S < b.S)
    		return 1;
    	if(a.S > b.S)
    		return 0;
    	if(a.F <= b.F)
    		return 1;
    	return 0;
    }
     
    const int N = (1e5) + 9;
    const int M = (672*672) + 9;
    const int LOGN = ((int)log2(N)) + 3;
    const int LOGM = ((int)log2(M)) + 3;
    const int BUCK = 900;
     
    int par[N], ht[N];
    vi vx[N], vy[N];
    set < int > st[N];
     
    int root(int n)
    {
    	while(par[n] != n)
    		n = par[n];
    	return n;
    }
     
    void merge(int a, int b)
    {
    	a = root(a);
    	b = root(b);
    	if(a == b)
    		return;
    	if(ht[a] >= ht[b])
    	{
    		ht[a] = max(ht[a], ht[b]+1);
    		par[b] = a;
    	}
    	else
    	{
    		ht[b] = max(ht[b], ht[a]+1);
    		par[a] = b;
    	}
    	return;
    }
     
    void solve()
    {
    	int n, i, j, x, y, a;
    	ll ans = 0;
    	cin >> n;
    	fo(i,1,N)
    	{
    		ht[i] = 1;
    		par[i] = i;
    	}
    	fo(i,1,n+1)
    	{
    		cin >> x >> y;
    		vx[x].pb(y);
    		vy[y].pb(x);
    	}
    	fo(i,1,N)
    		fo(j,1,sz(vy[i]))
    			merge(vy[i][0],vy[i][j]);
    	fo(i,1,N)
    	{
    		a = root(i);
    		for(auto x : vx[i])
    			st[a].insert(x);
    	}
    	fo(i,1,N)
    	{
    		a = root(i);
    		ans += sz(st[a]);
    	}
    	ans -= n;
    	cout << ans << '\n';
    	return;
    }
     
    int main()
    {
    	sws;
    	clock_t clk;
    	clk = clock();
    	// io_file;
    	// srand(clock());
     
    	//Code here
    	int t = 1, cs;
    	cout << fixed << setprecision(15);
    	// cin >> t;
    	fo(cs,1,t+1)
    	{
    		// cout << "Case #" << cs << ": ";
    		solve();
    	}
    	// Code ends here
     
    	clk = clock() - clk;
    	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    	return 0;
    }

Measured memory_bytes: 15872