#include <bits/stdc++.h>
using namespace std;using ll=long long;
using vl=vector<ll>;using vi=vector<int>;
using vs=vector<string>;using vc=vector<char>;
using vvl=vector<vl>;using pl=pair<ll,ll>;
using vvc=vector<vc>;using vd=vector<double>;
using vpl=vector<pl>;using vb=vector<bool>;
#define rep(i,r) for(ll i=0;i<(r);i++)
#define Rep(i,l,r) for(ll i=(l);i<(r);i++)
#define print(n) cout<<(n)<<endl
#define all(n) n.begin(),n.end()　
#define sortp(d) sort(all(d)) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
/*-----------順列生成-----------------
do 
{
}while(next_permutation(all(A)));
*/
//'A'65,'a'97
//cout<<fixed<<setprecision(9)<<;
ll gcd(ll a,ll b) {if(b==0)return a;else return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll modpow(ll a,ll n,ll mod) {ll res=1;while(n>0)
{if(n&1)res=res*a%mod;a=a*a%mod;n >>= 1;}return res;}
ll modinv(ll a,ll mod){return modpow(a, mod - 2, mod);}

ll p=0,q=0,r=0;
ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll inf=1000000000000; //10^12:∞
ll mod=1000000007; //10^9+7:合同式の法
struct edge{ll to,cost;};
const double pi = acos(-1);

int main()
{
  ll n;cin>>n;
  vpl a(pow(2,n));
  rep(i,pow(2,n)){ll x;cin>>x;a[i]={x,i+1};}
  p=pow(2,n-1);
  rep(i,n-1)
  {
    rep(j,p)
    {
      a[j]=max(a[2*j],a[2*j+1]);
 
    }
    p/=2;
  }
  if(a[0]>a[1])print(a[1].second);
  else print(a[0].second);
}
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
#define MOD 1000000007
#define MAX 1000005
using namespace std;

int main() {
	
	int N;
	cin >> N;
	vector<pair<int, string>> v;

	for (int i = 0; i < N; i++) {
		string name;
		int height;
		cin >> name >> height;
		v.push_back({ height,name });
	}

	sort(v.begin(), v.end());

	cout << v[v.size() - 2].second << endl;
}