#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int win(vector<int> rock){
    if(rock.size()==1)return rock[0];
    vector<int> rock1(rock.size()/2),rock2(rock.size()/2);
    REP(i,rock.size()/2){
        rock1[i]=rock[i];
        rock2[i]=rock[i+rock.size()/2];
    }
    int a=win(rock1);
    int b=win(rock2);
    if(a>b)return a-b;
    else if(a<b)return b-a;
    return a;
}

int main(){
    
    int N; cin>>N;
    vector<int> A(1<<N);
    REP(i,1<<N)cin>>A[i];
    
    cout<<win(A)<<endl;
    
    return 0;
}
