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

int main(){
    int N;
    cin >> N;
    vector<long long> b(N),M(N);
    
    long long A;
    cin >> A;
    b.at(0) = A;
    for(int i=1; i<N; i++){
        long long a;
        cin >> a;
        b.at(i) = b.at(i-1) + a;
    }
	M.at(0) = A;
    for(int i=1; i<N; i++){
    	M.at(i) = max(M.at(i-1), b.at(i));
    }
    
    long long ans = 0;
    long long x = 0;
    for(int i=0; i<N; i++){
       ans = max(ans, x + M.at(i));
       x = x + b.at(i);
    }

    cout << ans;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define VI vector<ll>
#define PB push_back
#define MM multimap
#define M map
#define MOD 100000007
#define PRII pair<ll,ll>
#define REP(i,n) for(ll i = 0;i<n;++i)
#define RES(i,n) for(ll i = n-1;i>=0;--i)
const int MAXN = 1e6+10;
const ull inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi  = acos(-1);
const double e = exp(1);
int sign(double a) {
	     if (a < -eps) return -1;
	else if (a >  eps) return  1;
	else               return  0;
}
struct Vector{
    double x,y;
};
double dis(Vector a,Vector b){
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
ll POW(ll a,ll b,ll m){
    if(!b)return 1;
    ll ans = POW(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
bool is_prime(ll n){
    if(n<=1)
        return 0;
    for(int i = 2;i*i<=n;++i)
        if(n%i==0)
            return 0;
    return 1;
}
ll t;
struct job{
    double c,w;
}a[50];
bool cmp(job a,job b){
    return a.c/a.w < b.c/b.w;
}
ull Stoi(string s){
    reverse(s.begin(),s.end());
    stringstream ss(s);
    ull num = 0;
    ss>>num;
    return num;
}
vector<pair<ll,ll>>v;
int main() {
    ll n;
    cin>>n;
    n = pow(2,n);
    REP(i,n){
        ll t;
        cin>>t;
        v.PB({t,i+1});
    }
    while(v.size()>2){
        n/=2;
        for(int i = 0;i<n;i++){
            if(v[i].first>v[i+1].first)
                v.erase(v.begin()+i+1);
            else
                v.erase(v.begin()+i);
        }
    }
    cout<<(ll)(v[0].first>v[1].first?v[1].second:v[0].second);
}