#include<stdio.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

ll judge(ll a,ll b){
    if(a>b)return a-b;
    if(b>a)return b-a;
    return a;
}

int main(void){
    int n;
    scanf("%d",&n);
    ll a[500000]={};
    ll k[500000]={};
    REP(i,1<<n)scanf("%lld",&a[i]);
    for(int i=n;i>=1;i--){
        ll num=1<<i;
        //printf("%lld\n",num);
        REP(j,num/2){
            k[j]=judge(a[j*2],a[j*2+1]);
            //printf("###%lld\n",k[j]);
        }
        //REP(j,num/2)printf("######%lld\n",k[j]);
        REP(j,num/2)a[j]=k[j];
    }
    printf("%lld\n",a[0]);
    return 0;
}