#include<cstdio>
#define for(a,b,c) for(int a=b;a<=c;a++)
typedef long long ll;
ll abs(ll a){return a>0?a:-a;}
ll a[1<<19];
int n;
int main(){
    scanf("%d",&n);
    int t=1<<n;
    for (i,1,t) scanf("%lld",&a[i]);
    t>>=1;
    while (t){
        int tot=0;
        for (i,1,t) a[++tot]=a[i<<1]==a[(i<<1)-1]?a[i<<1]:abs(a[i<<1]-a[(i<<1)-1]);
        t>>=1;
    }
    printf("%lld",a[1]);
}