#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin>>n;
  n=1<<n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  while(a.size()>=2){
    vector<int>b;
    for(int i=0; i<a.size()-1; i+=2){
      if(a[i]!=a[i+1])b.push_back(abs(a[i]-a[i+1]));
      else b.push_back(a[i]);
    }
    a=b;
  }
  cout<<a[0]<<endl;
}