#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

int main(){
    ll n;
    cin>>n;
    vector<pair<ll,string>> a;
    rep(i,n){
        string s;
        ll t;
        cin>>s>>t;
        a.emplace_back(t,s);
    }
    sort(a.rbegin(),a.rend());
    cout<<a[1].second<<endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// 任意MODが使えるModint 
// 型宣言の前にmodint::set_mod(MOD) をしてね
struct modint{
  long long x;

  modint() : x(0) {}
  modint(long long x):x(x%mod()){}

  static int &mod() {
    static int mod = 0;
    return mod;
  }

  static void set_mod(int md) {
    mod() = md;
  }

  modint& operator+=(const modint a){
    if((x+=a.x)>=mod()) x-=mod();
    return *this;
  }
  modint& operator-=(const modint a){
    if((x += mod()-a.x)>=mod()) x-=mod();
    return *this;
  }
  modint& operator*=(const modint a){
    (x*=a.x)%=mod();
    return *this;
  }
  modint operator+(const modint a) const{
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint a) const{
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint a) const{
    modint res(*this);
    return res*=a;
  }
  modint pow(long long t) const{
    if(!t) return 1;
    modint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  modint inv() const{
    return pow(mod()-2);
  }
  modint& operator/=(const modint a){
    return (*this) *= a.inv();
  }
  modint operator/(const modint a) const{
    modint res(*this);
    return res/=a;
  }
};


int main()
{
  ll a,b,c; cin >> a >> b >> c;
  a %= 10;
  ll st = a;
  vl vec(1, a);
  while(1) {
    a *= st;
    a %= 10;
    if(a == st) break;
    vec.push_back(a);
  }
//  for(auto tmp: vec) cout << tmp << "\n";
  ll n = sz(vec);
  ll mod=n;
  modint::set_mod(mod);
  modint x(b);
  modint y = x.pow(c);
//  cout << y.x << "\n";
  ll id = y.x;
  if(id == 0) id = n;
  cout << vec[id-1] << "\n";
  return 0;
}
