#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





/* Segment Tree */
class SegmentTree
{
private:
    long long n;    // 配列の要素数
    long long s;    // 配列を初期化するときの値
    vector<long long> data;     // セグメントツリーを持つ配列
public:
    SegmentTree(long long m, long long t);   // mは配列の要素数、tは配列を初期化するときの値
    long long operation(long long t1, long long t2); // 二項演算
    void update(long long k, long long a);  // k番目(0-indexed)の値をaに変更
    long long query(long long a, long long b);   // [a, b) の値を求める。外から呼ぶときはこっち
    long long ans(long long a, long long b, long long k, long long l, long long r);   // [a, b) の値を求める。
};

SegmentTree::SegmentTree(long long m, long long t){
    n = 1;
    
    while(n < m) n *= 2;
    
    for(long long i = 0; i < 2 * n - 1; i++){
        data.push_back(t);
    }
    
    s = t;
}

long long SegmentTree::operation(long long t1, long long t2){
    if(t1 == t2) return t1;
    return max(t1, t2) - min(t1, t2);
}

void SegmentTree::update(long long k, long long a){
    k += n - 1;
    data[k] = a;
    
    while(k > 0){
        k = (k - 1) / 2;
        data[k] = operation(data[k * 2 + 1], data[k * 2 + 2]);
    }
}

long long SegmentTree::query(long long a, long long b){
    return ans(a, b, 0, 0, n);
}

long long SegmentTree::ans(long long a, long long b, long long k, long long l, long long r){
    if(r <= a || b <= l) return s;
    if(a <= l && r <= b){
        return data[k];
    }
    else{
        long long vl = ans(a, b, k * 2 + 1, l, (l + r) / 2);
        long long vr = ans(a, b, k * 2 + 2, (l + r) / 2, r);
        
        return operation(vl, vr);
    }
}


int main() {
    ll n;
    cin >> n;
    SegmentTree tree(1 << n, 0);
    REP(i, 1 << n){
        ll a;
        cin >> a;
        tree.update(i, a);
    }
    cout << tree.query(0, 1 << n) << endl;
}
