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

int n;
struct CH
{
	string s;
	int v;
}Ty[1010];

bool cmp(CH x,CH y)
{
	return x.v>y.v;
}

template<typename Tp>
void read(Tp &x)
{
	x=0;int f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}

int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	{
		cin>>Ty[i].s;
		read(Ty[i].v);
	}
	sort(Ty+1,Ty+n+1,cmp);
	cout<<Ty[2].s<<endl;
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
// Hi 

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    string n;int k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        string a = n;
        sort(a.begin(),a.end());
        int an = 0,bn = 0;
        for(int i=0;i<(int)(a.size());i++){
            an = (an*10)+(a[i]-'0');
        }
        for(int i=(int)a.size()-1;i>=0;i--){
            bn = (bn*10)+(a[i]-'0');
        }
        n = to_string((bn-an));
    }
    cout << n << '\n';
    return 0;
}