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

const int inf = 1e18, mxn = 2e5;

// Global

void solve() {
   int n;
   cin >> n;
   vector<pair<int, string>> v(n);
   for (auto &i : v) {
      cin >> i.second >> i.first;
   }
   sort(v.begin(), v.end(), greater<>());
   cout << v[1].second << '\n';
}


signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   //   int t;
   //   cin >> t;
   //   while (t--)
   solve();
   return 0;
}
#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
const int N=1000005;
int h[N],nxt[N],adj[N],u,v,t,a[N],n,dep[N],fa[N],mn[N][20],path[N],dfn[N],cnp,ans[N];
/*
il int MIN(ct p,ct q){return dep[p]<dep[q]?p:q;}
il void lca(it u,it v){
	u=dfn[u],v=dfn[v],u>v?std::swap(u,v),0:0;
	ct k=LG[v-u+1];
	lc=MIN(mn[u][k],mn[v-(1<<k)+1][k]);
}
il int D(ct u,ct v){lca(u,v);return dep[u]+dep[v]-dep[lc]-dep[lc];}
il void ck(){
//	for(it i=1;i<=n;++i) printf("%d ",a[i]);puts("");
	for(it i=1;i<=n;++i)
		for(it j=i+1;j<=n;++j)
			if(D(i,j)>std::abs(a[i]-a[j])) return;
	for(it i=1;i<=n;++i) printf("%d ",a[i]);puts("");
	//exit(0);
}
il void Dfs(ct x){
	if(x>n) return ck();
	for(it i=1;i<=9;++i) a[x]=i,Dfs(x+1);
}
il void dfs(ct x){
	path[++cnp]=x,dep[x]=dep[fa[x]]+1,dfn[x]=cnp;
	for(it i=h[x],j;i;i=nxt[i])
		if((j=adj[i])^fa[x])
			fa[j]=x,dfs(j),path[++cnp]=x;
}
il void Pre(){
	LG[0]=-1;for(it i=1;i<=cnp;++i) mn[i][0]=path[i],LG[i]=LG[i>>1]+1;LG[0]=0;
	for(it j=1;j<=20;++j)
		for(it i=1;i+(1<<j)<=cnp;++i)
			mn[i][j]=MIN(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
}*/
int mxd,id;
int son[N];
bool flag[N];
il void dfs(ct x){
	path[++cnp]=x,dep[x]=dep[fa[x]]+1,dfn[x]=cnp;
	for(it i=h[x],j;i;i=nxt[i])
		if(((j=adj[i])^fa[x])&&(j^son[x]))
			fa[j]=x,dfs(j);
	if(son[x]) fa[son[x]]=x,dfs(son[x]);
	path[++cnp]=x;
}
il void predfs(ct x){
	flag[x]=(x==id);
	for(it i=h[x],j;i;i=nxt[i])
		if((j=adj[i])^fa[x]){
			fa[j]=x,predfs(j);
			if(flag[j]) son[x]=j,flag[x]=1;
		}
}
il void DFS(ct x,ct fa,ct dep){
	if(dep>mxd) mxd=dep,id=x;
	for(it i=h[x],j;i;i=nxt[i])
		if((j=adj[i])^fa)
			DFS(j,x,dep+1);
}
il void add(){nxt[++t]=h[u],h[u]=t,adj[t]=v,nxt[++t]=h[v],h[v]=t,adj[t]=u;}
int main(){ 
	scanf("%d",&n);it i;
	for(i=1;i<n;++i) scanf("%d%d",&u,&v),add();
	DFS(1,0,0),mxd=0,i=id,id=0,DFS(i,0,0),std::swap(i,id),predfs(i),dfs(i);
	for(i=cnp;i;--i) ans[path[i]]=i; 
	for(i=1;i<=n;++i) printf("%d ",ans[i]);
	//dfs(1),Pre();
	//for(it i=1;i<=n;++i) for(it j=i+1;j<=n;++j) printf("i=%d j=%d D(i,j)=%d\n",i,j,D(i,j));
	//Dfs(1);
	//for(it i=1;i<=cnp;++i) printf("%d ",path[i]);puts("");
	return 0;
}
