#include <iostream>
using namespace std;

int abs(int x){return x >= 0 ? x : -x;}

int main(){
	long long n;
	cin >> n;
	n = 1 << n;
	int tree[2 * n - 1];
	for(long long i = 0; i < n; i += 2){
		int l, r;
		cin >> l >> r;
		long long k = i + n - 1;
		tree[k] = l;
		tree[k + 1] = r;
		while(k > 0){
			k = (k - 1) / 2;
			tree[k] = tree[2 * k + 1] == tree[2 * k + 2] ? tree[2 * k + 1] : abs(tree[2 * k + 1] - tree[2 * k + 2]);
		}
	}
	cout << tree[0] << endl;
}