#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<pair<int,string>> data(n);
    for(int i=0;i<n;i++){
        cin>>data.at(i).second>>data.at(i).first;
    }
    sort(data.begin(),data.end());
    cout<<data.at(n-2).second<<endl;
}

#include <bits/stdc++.h>
#define LOCAL

using namespace std;

using ll = long long;
// const int MOD = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_vector(vector<ll> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        if (i < n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }
    }
}

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    while (b) {
        ll r = a % b; a = b; b = r;
    }
    return a;
}


inline void solve() {
    int n;
    cin >> n;

    vector<pair<int, string>> a(n);

    REP(i, n) {
        string s;
        int h;

        cin >> s >> h;
        a[i] = make_pair(h, s);
    }

    sort(ALL(a));

    cout << a[n-2].second << endl;

}

int main() {
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        // cout << "Case #" << _ << ": ";
        solve();
    }

    return 0;
}
