#include <iostream>
#include <queue>
using namespace std;

int battle(int x, int y) {
    if (x == y)
        return x;
    if (x < y)
        return y - x;
    return x - y;
}

int main() {
    int n;
    cin >> n;
    n = 1 << n;
    queue<int> que;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        que.push(a);
    }

    while (que.size() > 1) {
        int x = que.front(); que.pop();
        int y = que.front(); que.pop();
        que.push(battle(x, y));
    }
    cout << que.front() << endl;
}
