#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,n,a=1;
  cin>>n;
  queue<int> q;
  while(n--)a*=2;
  n=a;
  rep(i,n){
    cin>>a;
    q.push(a);
  }
  while(q.size()>1){
    int x=q.front();
    q.pop();
    int y=q.front();
    q.pop();
    if(x==y)q.push(x);
    else q.push(max(x,y)-min(x,y));
  }
  cout<<q.front()<<endl;
}
