#include <iostream>
#include <vector>

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(1<<n);
	for (long long int i = 0; i < (1<<n); i++) {
		cin >> a[i];
	}
	while (a.size() > 1) {
		vector<long long int> b;
		for (long long int i = 0; i < a.size(); i += 2) {
			if (a[i] > a[i+1]) {
				b.push_back(a[i]-a[i+1]);
			} else if (a[i] < a[i+1]) {
				b.push_back(a[i+1]-a[i]);
			} else {
				b.push_back(a[i]);
			}
		}
		a = b;
	}
	cout << a[0] << endl;
	return 0;
}