// Problem Link - 
/* By Navneet Shukla */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
//#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;	
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}


void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void file_i_o()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}
ll modularExponentiation(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modularExponentiation((x*x)%M,n/2,M);
    else                             
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
bool cmp(pair<string,int>p1,pair<string,int>p2)
{
	return p1.ss>p2.ss;
}
int main(int argc, char const *argv[]) {
	file_i_o();
	int n;
	cin>>n;
	vector<pair<string,int>>v;
	while(n--)
	{
		string s;
		int t;
		cin>>s>>t;
		v.push_back(make_pair(s,t));
	}
	sort(v.begin(),v.end(),cmp);
	cout<<v[1].ff<<endl;
	return 0;
}
#include<bits/stdc++.h>
#define maxn 400005
#define INF 0x3f3f3f3f
#define count cnt
using namespace std;
typedef long long ll;
int vis[maxn], viss[maxn];
vector<int > V[maxn];
int flg = 0;
int count = 0;
void dfs(int u, int fa) {
	viss[u]= 1;
	count++;
	for(int i=0;i<V[u].size();i++) {
		int v = V[u][i];
		if(v == fa) continue;
		if(viss[v]) {
			flg = 0;
			return;
		}
		dfs(v, u);
	}
	
}

int main() {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		vis[x] = vis[y] = 1;
		V[x].push_back(y);
		V[y].push_back(x);
	}
	int ans = 0;
	for(int i=1;i<=maxn-1;i++) {
		if(vis[i] && !viss[i]) {
			flg = 1;
			count = 0;
			dfs(i, 0);
			if(flg) ans += count-1;
			else ans += count;
		}
	}
	cout << ans << endl;
}