#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

#define reep(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) reep(i,0,n)

int a[1000000];

int main(){
    int n;
    cin >> n;
    int N=1;
    rep(i,n){
        N*=2;
    }

    rep(i,N){
        cin >> a[i];
    }

    int right=N;
    rep(i,n){
        for(int k=0;k<right;k+=2){
            if(a[k]!=a[k+1]){
                a[k/2] = abs(a[k]-a[k+1]);
            }
        }
        right /= 2;
    }
    cout << a[0] << endl;
}