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


#define  quick  ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define sr(x) sort(x.begin(),x.end(),greater<ll>())
#define v1 vector<ll>
#define s1 set<ll>
#define p1 pair<ll,ll>
#define m1 map<ll,ll>
#define take(v,n) for(i=0;i<n;i++)    cin>>v[i];
#define print(v,n) for(i=0;i<n;i++)    cout<<v[i]<<" ";
#define ff first
#define ss second
#define ee '\n';
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define f(i,x,y) for(i=x;i<y;i++)
#define mp make_pair
#define yes cout<<"Yes"<<endl
#define no  cout<<"No"<<endl

bool sortbysec(const pair<string,ll> & a, const pair<string,ll> & b)
{
    return (a.second < b.second);
}

void solve()
{
        ll n,i;
        cin>>n;
        vector<pair<string,ll>> p;
        f(i,0,n)
        {
                  ll y;
                  string s;
                  cin>>s>>y ; 
                  p.pb(mp(s,y));
        }
        sort(all(p), sortbysec);
        cout<<p[p.size()-2].ff<<ee;
}

 int32_t main()
 {
    quick;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       solve();
    }
    return 0;
 }
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"

const ll MOD = 998244353;


ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

template<typename T> T signum(T a) { 
    return (a > 0) - (a < 0); 
}

template<typename T> T cmp(T a, T b) { 
    return signum(a-b); 
}

template<typename T> bool mins(T& lhs , T& rhs) {
    if (rhs < lhs) {
        lhs = rhs;
        return true;
    }

    return false;
}

template<typename T> bool maxs(T& lhs , T& rhs) {
    if (rhs > lhs) {
        lhs = rhs;
        return true;
    }

    return false;
}


const int MAX = INT_MAX;

void gks(int tc) {
    printf("Case #%d: ", tc);
};


int main() {
    int n;
    cin>>n;
    vector<pair<int, string>>  a(n);
    for (int i = 0;i < n;++i) {
        cin>>a[i].second>>a[i].first;
    }

    auto cmp = [&] (const pair<int, string>& lhs, const pair<int, string>& rhs) {
        return lhs.first > rhs.first;
    };

    sort(all(a), cmp);
    cout<<a[1].second<<nl;

   return 0;
}
