#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> A(1 << N);
		for(int i = 0; i < 1 << N; ++ i)
			scanf("%d", &A[i]);
		rep(k, N) {
			vi nA(1 << (N - k - 1));
			rep(i, 1 << (N - k - 1)) {
				int X = A[i * 2 + 0], Y = A[i * 2 + 1];
				if(X == Y)
					nA[i] = X;
				else
					nA[i] = max(X, Y) - min(X, Y);
			}
			A.swap(nA);
		}
		int ans = A[0];
		printf("%d\n", ans);
	}
	return 0;
}
