#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double dd;

void solve(ll test_num) {
  (void) test_num;
  ll N;
  cin >> N;
  N = 1 << N;
  vector<ll> arr(N);
  for (ll& a : arr) {
    cin >> a;
  }
  while (arr.size() > 1UL) {
    vector<ll> narr;
    for (ll i = 1; i < (ll) arr.size(); i += 2) {
      if (arr[i] == arr[i - 1]) {
        narr.push_back(arr[i]);
      } else {
        narr.push_back(max(arr[i], arr[i - 1]) - min(arr[i], arr[i - 1]));
      }
    }
    arr = narr;
  }
  cout << arr[0] << endl;
}

void init() {

}

int main() {
#ifdef AZN
  const auto start_time = chrono::system_clock::now();
  freopen("/home/azneye/Documents/Stuff/input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  ll tests = 1;
  //cin >> tests;
  for (ll test = 1; test <= tests; ++test) {
    solve(test);
  }
#ifdef AZN
  cerr << "Took: " << ((chrono::system_clock::now() - start_time).count() / 1e9) << " s" << endl;
#endif
  return 0;
}