//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	mii ma;
	vpr va;
	rep(i,0,n){
		cin>>x>>y;
		if(x!=y)
			ma[y]=1;
		va.pb(mp(x,y));
	}
	for(auto x:va){
		if(ma[x.aa]==0)c++;
	}

	cout<<c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	mii ma;
	vpr va;
	rep(i,0,n){
		cin>>x>>y;
		ma[x]++;
		va.pb(mp(x,y));
	}

	for(auto x: va){
		if(x.aa==x.bb || ma[x.bb]==0)c++;
	}
	cout<<c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	rep(i,0,n){
		cin>>x>>y;
		if(x==y)c++;

	}

	cout<<c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,n;
  map<int ,int>mp;
  set<int>s;
  cin>>n;
  int c=0,c1=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a!=b){
      mp[b]=1;
    }
    s.insert(a);
    s.insert(b);
    }
    for(auto i=s.begin();i!=s.end();i++){
      if(mp[*i]==0)
        c++;
    }
    cout<<c;
  return 0;
}


//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	mii ma,mb;
	vpr va;
	rep(i,0,n){
		cin>>x>>y;
		ma[x]=1;
		va.pb(mp(x,y));
	}
	for(auto x:va){
		if(x.aa!=x.bb && mb[x.aa]==0 && ma[x.bb]==1){
			mb[x.aa]=1;
		}
	}
	for(auto x:va){
		if(mb[x.aa]==0)c++,mb[x.aa]=1;
	}

	cout<<c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	vll a,b;
	rep(i,0,n){
		cin>>x>>y;
		a.pb(x);
		b.pb(y);
	}
	for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (i != j) {
                if (a[i] == b[j]) {
                    c++;
                    break;
                }
            }
        }
    }

	cout<<n-c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	mii ma,mb;
	vpr va;
	rep(i,0,n){
		cin>>x>>y;
		ma[x]=1;
		va.pb(mp(x,y));
	}
	for(auto x:va){
		if(x.aa!=x.bb && mb[x.aa]==0 && ma[x.bb]==1){
			mb[x.aa]=1;
		}
	}
	for(auto x:va){
		if(mb[x.aa]==0)c++;
	}

	cout<<c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,n;
  map<int ,int>mp;
  cin>>n;
  int c=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a!=b && mp[b]==0){
      mp[b]=1;
    }
  }
  for(int i=1; i<=n;i++)
    if(mp[i]==1)c++;
  cout<<c;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,n;
  map<int ,int>mp;
  set<int>s;
  cin>>n;
  int c=0,c1=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a!=b && mp[b]==0){
      mp[b]=1;
    }
    if(a>0 && a<=n)
      s.insert(a);
    if(b>0 && b<=n)
      s.insert(b);
  }
  for(int i=1; i<=n;i++)
    if(mp[i]==1)c++;
  cout<<s.size()-c;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,n;
  map<int ,int>mp;
  cin>>n;
  int c=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a!=b && mp[b]==0){
      c++;
      mp[b]=1;
    }
  }
  cout<<n-c;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,n;
  map<int ,int>mp;
  set<int>s;
  cin>>n;
  int c=0,c1=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a!=b){
      mp[b]=1;
    }
    s.insert(a);
    }
    for(auto i=s.begin();i!=s.end();i++){
      if(mp[*i]==1)
        c++;
    }
    cout<<s.size()-c;
  return 0;
}


//Author : nova king
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define cti(c) c-'0'
#define rep(i,j,k) for(i=j;i<k;i++)
#define per(i,k) for(i=k;i>=0;i--)
#define pb push_back
#define nl cout<<"\n";
#define vll vector<ll>
#define umii unordered_map<ll,ll>
#define vov vector<vll>
#define vst vector<string>
#define vch vector<char>
#define pii pair<ll,ll>
#define vpr vector<pii>
#define psi pair<string,ll>
#define pis pair<ll,string>
#define pci pair<char,ll>
#define pic pair<ll,char>
#define msi map<string,ll>
#define mci map<char,ll>
#define mis map<ll,string>
#define mic map<ll,char>
#define mss map<string,string>
#define mii map<ll,ll>
#define mp make_pair
#define ld double
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())
#define stp(x) cout<<setprecision(x)<<fixed
#define aa first
#define bb second
#define be begin()
#define en end()
#define si size()
#define le length()
#define imin LONG_LONG_MIN
#define imax LONG_LONG_MAX
#define INF 0x3f3f3f3f
#define all(v) v.begin(),v.end()
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define PI 3.14159265358979323846
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ost;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
ll mod=1000000007;

ll binaryexpo(ll a,ll b,ll mod){
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0){
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}
ll mulmod(ll x,ll n,ll mod){
	ll result=1;
	while(n>0){
		if(n%2==1) result=binaryexpo(result,x,mod);
		//cout<<result<<"\n";
		x=binaryexpo(x,x,mod);
		n/=2;
	}
	return result;
}

ll getSum(ll n) {
    ll sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }

vector<bool>prime(10000001,true);
void printpri(ll x){

		int k=0;
		prime[1]=false;
	for(int i=2;i*i<=x;i++){
		if(prime[i]==true){

			for(int j=i*i;j<=x;j+=i){
				prime[j]=false;
			}
		}
	}
	/*
	for(int i=l;i<=r;i++)
		if(prime[i]){
			cout<<i<<" ";
		}*/
}

double getEuclidean(pair<int,int> p1,pair<int,int> p2){
	return sqrt(pow(p2.aa-p1.aa,2)+pow(p2.bb-p1.bb,2));
}
ll bsearch(ll l ,ll r,ll k,ll n){
	ll m=r,s=0;
	while(l<=r){
		m=l+(r-l)/2;
		s=0;
		ll x=k,p=1,i=0;
		while(m>=p && s<n){
			s+=m/p;
			i++;
			p=pow(x,i);
		}
		//dbg2(m,s);
		if(s>=n)
			r=m-1;
		else
			l=m+1;

	}
	if(s<n)
		return m+1;
	else return m;
}
ll getnear2power(ll n){
	ll a=(ll)log2(n);
	return pow(2,a);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll d,v,s,i,t,j,n,m,r,q,z,f,p,l,a,b,x,c,k,e,y;
void solve(){
	cin>>n;
	c=0;
	mii ma,mb;
	vpr va;
	rep(i,0,n){
		cin>>x>>y;
		if(x==y)mb[x]++;
		if(x!=y)ma[y]++;
		va.pb(mp(x,y));
	}
	for(auto x:va){
		if(ma[x.aa]==0 && mb[x.aa]<2)c++;
	}

	cout<<c;

}

int  main(){

	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	solve();
  	nl;
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,n;
  map<int ,int>mp;
  cin>>n;
  int c=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a!=b && mp[b]==0){
      mp[b]=1;
    }
  }
  for(int i=1; i<=n;i++)
    if(mp[i]==1)c++;
  cout<<n-c;
  return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,x,y;
cin>>n;
unordered_map<int,vector<int>> pairs;
fr(i,0,n){
    cin>>x>>y;
    pairs[x].pub(y);
}
int ans=0;
for(auto x:pairs)
    for(auto y:x.second)
        if(x.first == y || pairs.find(y)==pairs.end())
            ans++;
cout<<ans;
return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){
// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif4

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n;
cin>>n;
vector<vector<int>> pairs(n,vector<int>(3));
fr(i,0,n){
    cin>>pairs[i][0]>>pairs[i][1];
    pairs[i][2]=0;
}
int ans=0;
fr(i,0,n)
    fr(j,0,n)
        if(i!=j && pairs[i][1]==pairs[j][0] && pairs[j][2]==0){
            ans++;
            pairs[j][2]=1;
        }
cout<<n-ans;
return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,x,y;
cin>>n;
unordered_map<int,vector<int>> pairs;
fr(i,0,n){
    cin>>x>>y;
    pairs[x].pub(y);
}
int ans=n;
for(auto x:pairs)
    for(auto y:x.second)
        if(x.first != y && pairs.find(y)!=pairs.end())
            ans-=x.second.size();
cout<<ans;
return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,x,y;
cin>>n;
unordered_map<int,vector<int>> pairs;
fr(i,0,n){
    cin>>x>>y;
    pairs[x].pub(y);
}
int ans=pairs.size();
for(auto x:pairs)
    for(auto y:x.second)
        if(x.first != y && pairs.find(y)!=pairs.end())
            ans-=x.second.size();
cout<<ans;
return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif4

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,x,y;
cin>>n;
unordered_map<int,vector<int>> pairs;
fr(i,0,n){
    cin>>x>>y;
    pairs[x].pub(y);
}
int ans=n;
for(auto x:pairs)
    for(auto y:x.second)
        if(x.first != y && pairs.find(y)!=pairs.end())
            ans-=pairs[y].size();
cout<<ans;
return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif4

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,x,y;
cin>>n;
unordered_map<int,vector<int>> pairs;
unordered_map<int,int> visited;
fr(i,0,n){
    cin>>x>>y;
    pairs[x].pub(y);
    visited[x]++;
}
int ans=0;
for(auto x:pairs)
    for(auto y:x.second)
        if(x.first != y && visited.find(y)!=visited.end() && visited[y]){
            ans+=visited[y];
            visited[y]=0;
        }
cout<<n-ans;
return 0;
}


// Author:Sh2w

#include<bits/stdc++.h>
#define str string
#define ll int64_t
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fl(i,a,b) for(ll i=a;i>=b;i--)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define vs(x) vector<x>
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define itr ::iterator
#define ritr ::reverse_iterator
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

using namespace std;

int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int n,x,y;
cin>>n;
unordered_map<int,int> pairs;
fr(i,0,n){
    cin>>x>>y;
    pairs[x]=y;
}
int ans=0;
for(auto x:pairs)
    if(x.first == x.second || pairs.find(x.second)==pairs.end())
        ans++;
cout<<ans;
return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

int main()
{
    int n, x, y, cnt = 0;
    bool vis[100123];

    cin >> n;
    cnt = n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        cnt -= ( x != y || vis[y] );
        vis[y] = ( x != y );
    }

    cout << cnt;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

bool vis[1234];
vi Aj[1234];

int main()
{
    int n, x, y;
    set < int > s;
    mem ( vis, 1 );

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        if ( x != y ) Aj[x].PB ( y );
        s.insert ( x ), s.insert ( y );
    }

    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        for ( int j = 0; j < sz ( Aj[*i] ); j++ ) {
            vis[Aj[*i][j]] = 0;
        }
    }

    int ans = 0;
    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        ans += vis[*i];
    }

    cout << ans;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

int main()
{
    int n, x, y, cnt = 0;
    bool vis[100123];

    cin >> n;
    cnt = n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        cnt -= ( x != y );
    }

    cout << cnt;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

bool vis[1234];
vi Aj[1234];

int main()
{
    int n, x, y;
    set < int > s;
    map < int , int > m;
    mem ( vis, 0 );

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        if ( x != y ) Aj[x].PB ( y );
        else if ( m[x] > 1 ) Aj[x].PB ( y );
        s.insert ( x );
        m[x]++;
    }

    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        for ( int j = 0; j < sz ( Aj[*i] ); j++ ) {
            vis[Aj[*i][j]] = 1;
        }
    }

    int ans = 0;
    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        if ( !vis[*i] ) ans += m[*i];
    }

    cout << ans;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

int main()
{
    int n, x, y, ans = 0;
    pii p;
    vector < pii > v;

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        v.PB ( { x, y } );
    }

    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            if ( i == j ) continue;
            if ( v[i].S == v[j].F ) {
                ans++;
                v[j].F = -1;
            }
        }
    }

    cout << n-ans;
    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

bool vis[1234];
vi Aj[1234];

int main()
{
    int n, x, y;
    set < int > s;
    mem ( vis, 1 );

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        if ( x != y ) Aj[x].PB ( y );
        s.insert ( x );
    }

    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        for ( int j = 0; j < sz ( Aj[*i] ); j++ ) {
            vis[Aj[*i][j]] = 0;
        }
    }

    int ans = 0;
    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        ans += vis[*i];
    }

    cout << ans;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

bool vis[1234];
vi Aj[1234];

int main()
{
    int n, x, y;
    set < int > s;
    map < int , int > m;
    mem ( vis, 0 );

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        if ( x != y ) Aj[x].PB ( y );
        s.insert ( x );
        m[x]++;
    }

    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        for ( int j = 0; j < sz ( Aj[*i] ); j++ ) {
            vis[Aj[*i][j]] = 1;
        }
    }

    int ans = 0;
    for ( set < int > :: iterator i = s.begin(); i != s.end(); i++ ) {
        if ( !vis[*i] ) ans += m[*i];
    }

    cout << ans;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

int main()
{
    int n, x, y;
    bool vis[100123];

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        if ( x != y ) vis[y] = 1;
    }

    int cnt = 0;
    for ( int i = 0; i <= 10000; i++ ) cnt += vis[i];
    cout << n-cnt;

    return 0;
}


/*In the name of Almighty Allah*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define PB push_back
//#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mid(l,r) ((r+l)/2)
#define left(node) (node*2)
#define right(node) (node*2+1)
#define mx_int_prime 999999937

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

struct edge {
    int u, v, w;
};

bool cmp ( const edge &a, const edge &b )
{
    return a.w < b.w;
}

string to_s(int t)
{
  stringstream ss;
  ss << t;
  return ss.str();
}

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
//#ifdef shahriar
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
//#else
//#define dbg(args...)
//#endif // shahriar

int main()
{
    int n, x, y, cnt = 0;
    bool vis[100123];

    cin >> n;
    cnt = n;
    for ( int i = 0; i < n; i++ ) {
        cin >> x >> y;
        cnt -= ( x != y || vis[y] );
        vis[y] = ( x != y || vis[y] );
    }

    cout << cnt;

    return 0;
}


#include <iostream>
#include <vector>
//#include <pair>
using namespace std;

int main(){
	int n;
	cin>>n;
	int mark[4000]={0};
	int count[4000]={0};
	vector<pair<int,int >> v;
	int a,b;
	for (int i=0;i<n;i++){
		cin>>a>>b;
		v.push_back(make_pair(a,b));
		mark[b] = 1;
		count[a]++;
	}

	int c=0;
	for (int i=0;i<v.size();i++)
		if(mark[v[i].first] == 0 || ( mark[v[i].first] == 1 && count[v[i].first] <= 1) )
			c++;

	cout<<c<<endl;
}


#include <iostream>
using namespace std;

int main(){
	int n;
	int arr[n];
	int brr[n];
	cin>>n;

	for (int i=0;i<n;i++){
		cin>>arr[i];
		cin>>brr[i];
	}

	int count=0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (arr[i] == brr[j] && i != j){
				count++;
				break;
			}
		}
	}

	cout<<(n-count)<<endl;
}


#include <iostream>
#include <vector>
//#include <pair>
using namespace std;

int main(){
	int n;
	cin>>n;
	int mark[4000]={0};
	int count[4000]={0};
	int same[4000]={0};
	vector<pair<int,int >> v;
	int a,b;
	for (int i=0;i<n;i++){
		cin>>a>>b;
		v.push_back(make_pair(a,b));
		if (a != b)
			mark[b] = 1;
		else{
			same[b] = 1;
			count[a]++;
		}
	}

	int c=0;
	for (int i=0;i<v.size();i++)
		if(mark[v[i].first] == 0)
			if ((same[v[i].first] == 1 && count[v[i].first] <= 1) || (same[v[i].first] == 0 ))
				c++;

	cout<<c<<endl;
}


#include <iostream>
using namespace std;

int main(){
	int n;
	cin>>n;

	int arr[n];
	int brr[n];

	for (int i=0;i<n;i++){
		cin>>arr[i];
		cin>>brr[i];
	}

	int count=0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (arr[i] == brr[j] && i != j){
				count++;
				break;
			}
		}
	}

	cout<<(n-count)<<endl;
}


#include <iostream>
#include <vector>
//#include <pair>
using namespace std;

int main(){
	int n;
	cin>>n;
	int mark[4000]={0};
	int count[4000]={0};
	int same[4000]={0};
	vector<pair<int,int >> v;
	int a,b;
	for (int i=0;i<n;i++){
		cin>>a>>b;
		v.push_back(make_pair(a,b));
		if (a != b)
			mark[b] = 1;
		else{
			same[b] = 1;
			count[a]++;
		}
	}

	int c=0;
	for (int i=0;i<v.size();i++)
		if(mark[v[i].first] == 0 && ( same[v[i].first] == 1 && count[v[i].first] <= 1) )
			c++;

	cout<<c<<endl;
}


#include <iostream>
#include <algorithm>
using namespace std;

int find (int n,int *arr, int val){
	sort(arr,arr+n);
	int s=0,e=n-1;
	int mid;
	while (s <= e){
		mid = s + (e-s)/2;
		if (arr[mid] == val)
			return 1;
		else  if (arr[mid ] > val)
			e = mid - 1;
		else if (arr[mid] < val)
			s = mid + 1;
	}
	return 0;
}
int main(){
	int n;
	cin>>n;
	int bot[n],op[n];
	for (int i=0;i<n;i++) cin>>bot[i]>>op[i];

	int c=0;
	for (int i=0;i<n;i++){
		if (bot [i] == op [i])
		{
			c++;
		}
		else {
			int ans = find (n,bot,op[i]);
			if (ans == 0)
				c++;
		}
	}
	cout<<c<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main(){
	int n;
	int arr[n],brr[n];
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>arr[i]>>brr[i];
	}

	int count=0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (arr[i] == brr[j] && i != j){
				count++;
				break;
			}
		}
	}

	cout<<n-count<<endl;
}


#include <iostream>
#include <vector>
//#include <pair>
using namespace std;

int main(){
	int n;
	cin>>n;
	int mark[4000]={0};
	vector<pair<int,int >> v;
	int a,b;
	for (int i=0;i<n;i++){
		cin>>a>>b;
		v.push_back(make_pair(a,b));
		if (a != b)
			mark[b] = 1;
	}

	int c=0;
	for (int i=0;i<v.size();i++)
		if(mark[v[i].second] == 0 )
			c++;

	cout<<c<<endl;
}


#include <iostream>
#include <vector>
//#include <pair>
using namespace std;

int main(){
	int n;
	cin>>n;
	int mark[4000]={0};
	vector<pair<int,int >> v;
	int a,b;
	for (int i=0;i<n;i++){
		cin>>a>>b;
		v.push_back(make_pair(a,b));
		if (a != b)
			mark[b] = 1;
	}

	int c=0;
	for (int i=0;i<v.size();i++)
		if(mark[v[i].first] == 0 )
			c++;

	cout<<c<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] == b[j] && i != j) ans++;
        }
    }
    cout << n - ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, a, b;
    cin >> n;
    bool vis[n + 10];
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        if (a != b) {
            vis[b] = 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans++;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    bool vis[2000], vis1[2000];
    memset(vis, 0, sizeof(vis));
    memset(vis1, 0, sizeof(vis1));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] == b[i]) ans--;
        vis[b[i]] = 1;
    }
    for (int i = 0; i < n; i++) {
        if (vis[b[i]]) ans++;
    }
    cout << n-ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (b[i] == a[j] && i != j) ans++;
        }
    }
    cout << n - ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    bool vis1[n + 10], vis2[n + 10];
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        vis1[a[i]] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j && b[j] == a[i]) {
                ans++;
            }
        }
    }
    cout << n - ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    bool vis1[1010], vis2[1010];
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        vis1[a[i]] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i] && vis1[a[i]]) {
            vis2[b[i]] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (vis2[i] != 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    bool vis1[n + 10], vis2[n + 10];
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        vis1[a[i]] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i] && vis1[a[i]]) {
            vis2[b[i]] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (vis2[i] != 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin>>n;
    bool vis[n+10];
    memset(vis,0,sizoef(vis));
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(a!=b){
            vis[b]=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans++;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n + 10], b[n + 10];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j && b[j] == a[i]) {
                ans++;
                break;
            }
        }
    }
    cout << n - ans << endl;
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c,d,i;
    cin>>d;
    c=0;
    for(i=0;i<d;i++)
    {
        cin>>a>>b;
        if(a==b)
            c++;
    }
    cout<<c<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    int a[10000],b[10000],c,d,i;
    cin>>d;
    c=0;
    map<int,int>w;
    for(i=0;i<d;i++)
    {
        cin>>a[i]>>b[i];
        w[a[i]]++;
    }
    for(i=0;i<d;i++)
    {
        if(a[i]!=b[i])
        {
            if(w[b[i]]>0)
            {
                c+=w[b[i]];
                w[b[i]]=0;
            }
        }
    }
    cout<<d-c<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    int a[10000],b[10000],c,d,i,p;
    cin>>d;
    c=0;
    map<int,int>w,z;
    for(i=0;i<d;i++)
    {
        cin>>a[i]>>b[i];
        w[a[i]]++;
        z[b[i]]++;
    }
    for(i=0;i<d;i++)
    {
        if(a[i]==b[i])
        {
            if(w[b[i]]>1)
            {
                c+=(w[b[i]]-1);
                w[b[i]]=0;
                if(z[b[i]]>1)
                c++;
            }
        }
        if(a[i]!=b[i])
        {
            if(w[b[i]]>0)
            {
                c+=w[b[i]];
                w[b[i]]=0;
            }
        }
    }
    cout<<d-c<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    int a[10000],b[10000],c,d,i;
    cin>>d;
    c=0;
    map<int,int>w;
    for(i=0;i<d;i++)
    {
        cin>>a[i]>>b[i];
        w[a[i]]++;
    }
    for(i=0;i<d;i++)
    {
        if(a[i]!=b[i])
        {
            if(w[b[i]]>0)
                c++;
        }
    }
    cout<<d-c<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    int a[10000],b[10000],c,d,i,p;
    cin>>d;
    c=0;
    map<int,int>w;
    for(i=0;i<d;i++)
    {
        cin>>a[i]>>b[i];
        w[a[i]]++;
    }
    for(i=0;i<d;i++)
    {
        if(a[i]==b[i])
        {
            if(a[b[i]]>1)
            {
                c+=w[b[i]];
                w[b[i]]=0;
            }
        }
        if(a[i]!=b[i])
        {
            if(w[b[i]]>0)
            {
                c+=w[b[i]];
                w[b[i]]=0;
            }
        }
    }
    cout<<d-c<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
    int a[10000],b[10000],c,d,i;
    cin>>d;
    c=0;
    map<int,int>w;
    for(i=0;i<d;i++)
    {
        cin>>a[i]>>b[i];
        w[b[i]]++;
    }
    for(i=0;i<d;i++)
    {
        if(a[i]!=b[i])
        {
            if(w[a[i]]>0)
                c++;
        }
    }
    cout<<d-c<<endl;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
long long a[1000005],x,ANS,ans[100005];
int o,y,i,n,j,now,k;
map <long long,int> mp;
struct node {long long x;int y,z;} t[1000005];
int cmp(node i,node j) {return i.x>j.x;}
int main()
{
    scanf("%d",&n);
    for (i=1; i<=n; i++) scanf("%I64d",&a[i]);
    y=1;
    for (i=1; i<=12; i++)
    {
        y=y*107%n+1; mp.clear(); now=o=0;
        for (j=1; j<=n; j++)
        {
            x=__gcd(a[j],a[y]);
            if (mp[x]==0) ans[++o]=x; mp[x]++;
        }
        for (j=1; j<=o; j++) t[j].x=ans[j],t[j].y=mp[ans[j]],t[j].z=0;
        sort(t+1,t+o+1,cmp);
        for (j=1; j<=o; j++)
        {
            if (t[j].y+t[j].z>n/2-1+n%2) {ANS=max(ANS,t[j].x); break;}
            for (k=j+1; k<=o; k++) if (t[j].x%t[k].x==0) t[k].z+=t[j].y;
        }
    }
    cout<<ANS;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
long long Y,ANS,A[1000005];
int n,x,i,j,o,O,k,p[1000005],B[1000005],c[1000005];
struct node {long long x;int y,z;} b[1000005];
int cmp(long long i,long long j) {return b[i].x<b[j].x;}
map <long long,int>mp;
int main()
{
    scanf("%d",&n);
    for (i=1; i<=n; i++) scanf("%I64d",&A[i]);
    x=1;
    for (i=1; i<=n; i++) B[i]=i;srand(0);
    random_shuffle(B+1,B+n+1);
    for (i=1; i<=14; i++)
    {
        mp.clear();
        x=B[i%n+1]; O=0;
        for (j=1; j<=n; j++) if (j!=x)
        {
            Y=__gcd(A[x],A[j]);
            if (mp[Y]) mp[Y]++; else {mp[Y]=1; b[++O].x=Y;}
        }
        for (j=1; j<=O; j++) {c[j]=j; b[j].y=mp[b[j].x]; b[j].z=0;}
        sort(c+1,c+O+1,cmp);
        for (j=O; j>=1; j--)
        {
            if (b[c[j]].y+b[c[j]].z>=(n-1)/2) {ANS=max(ANS,b[c[j]].x); break;}
            for (k=j-1; k>=1; k--) if (b[c[j]].x%b[c[k]].x==0) b[c[k]].z+=b[c[j]].y;
        }
    }
    cout<<ANS;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
long long ANS,A[1000005],a[1000005];
int n,x,i,j,o,O,k,p[1000005],B[1000005];
int cmp(long long i,long long j) {return i<j;}
struct node {long long x;int y,z;} b[1000005];
int main()
{
    scanf("%d",&n);
    for (i=1; i<=n; i++) scanf("%I64d",&A[i]);
    x=1;
    for (i=1; i<=n; i++) B[i]=i;
    random_shuffle(B+1,B+n+1);
    for (i=1; i<=12; i++)
    {
        x=B[i%n+1];
        for (j=1; j<=n; j++) if (j!=x) a[++o]=__gcd(A[x],A[j]);
        sort(a+1,a+o+1,cmp); O=0;
        for (j=1; j<=o; j++)
          if (a[j]!=a[j-1]) {b[++O].x=a[j]; b[O].y=1; b[O].z=0;}else b[O].y++;
        for (j=O; j>=1; j--)
        {
            if (b[j].y+b[j].z>=(n-1)/2) ANS=max(ANS,b[j].x);
            for (k=j-1; k>=1; k--) if (b[j].x%b[k].x==0) {b[k].z+=b[j].y;break;}
        }
    }
    cout<<ANS;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
long long ANS,A[1000005],a[1000005];
int n,x,i,j,o,O,k,p[1000005],B[1000005];
int cmp(long long i,long long j) {return i<j;}
struct node {long long x;int y,z;} b[1000005];
int main()
{
    scanf("%d",&n);
    for (i=1; i<=n; i++) scanf("%I64d",&A[i]);
    x=1;
    for (i=1; i<=n; i++) B[i]=i;
    random_shuffle(B+1,B+n+1); srand(0);
    for (i=1; i<=12; i++)
    {
        x=B[i%n+1]; o=0;
        for (j=1; j<=n; j++) if (j!=x) a[++o]=__gcd(A[x],A[j]);
        sort(a+1,a+o+1,cmp); O=0;
        for (j=1; j<=o; j++)
          if (a[j]!=a[j-1]) {b[++O].x=a[j]; b[O].y=1; b[O].z=0;}else b[O].y++;
        for (j=O; j>=1; j--)
        {
            if (b[j].y+b[j].z>=(n-1)/2) {ANS=max(ANS,b[j].x); break;}
            for (k=j-1; k>=1; k--) if (b[j].x%b[k].x==0) b[k].z+=b[j].y;
        }
    }
    cout<<ANS;
    return 0;
}