#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define f first
#define s second
#define pii pair<int,int>


const int N =3e5+5;
const int MOD = 1e9+7;
const ll M = 1e18;

ll qpow(ll a, ll b, ll m)
{
    ll  ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

vector<pii>adj[400005];
bool vis[400005];
bool graph = false;
set<int>ver;

void dfs(int v, int par, int edge_n){
    if(par>0){
        if(vis[v]){
            graph = true;
            return;
        }
    }
    if(vis[v]) return;
    ver.insert(v);
    vis[v] = true;
    for(pii p:adj[v]){
        int u = p.f, edg = p.s;
        if(u!=par){
            dfs(u, v, edg);
        }
    }
}

int main()
{
	IOS;
	
	int t=1; //cin>>t;
	while(t--){
	   int n; cin>>n;
	   int a,b;
	   set<int>ss;
	   for(int i=0;i<n;i++){
	       cin>>a>>b;
	       ss.insert(a);
	       ss.insert(b);
	       adj[a].push_back(make_pair(b,i));
	       adj[b].push_back(make_pair(a,i));
	   }
	   int ans = 0;
	   for(auto it = ss.begin();it!=ss.end();it++){
	       ver.clear();
	       int k = *it;
	       if(vis[k]==0){
	           graph = false;
	           dfs(k,0,0);
	           if(graph)
	             ans += ver.size();
	           else ans+= ver.size()-1;  
	       }
	   }
	   cout<<ans;
	   
	   cout<<endl;
    }
    
}



#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=4e5;
typedef int fuko[yuzu|10];
fuko fa,sz;
struct dsu {  
  int find(int x) {
    return fa[x]?fa[x]=find(fa[x]):x;
  }
  int mg(int u,int v) {
    u=find(u),v=find(v);
    if (sz[u]&&sz[v]) return 0;
    u^v?fa[u]=v,sz[v]|=sz[u]:sz[u]=1;
    return 1;
  }
}zw;
int main() {
  int n,i,a,b,lxy=0;
  read(n);
  for (i=1;i<=n;++i) lxy+=zw.mg(read(),read());
  printf("%d\n",lxy);
}