#include<iostream>
#include<vector>
using namespace std;
vector<int>vec;
int n, a;
int main() {
	cin >> n;
	for (int i = 0; i < (1 << n); i++) { cin >> a; vec.push_back(a); }
	while (vec.size() >= 2) {
		vector<int>vec2;
		for (int i = 0; i < vec.size(); i += 2) {
			if (vec[i] == vec[i + 1])vec2.push_back(vec[i]);
			if (vec[i] > vec[i + 1])vec2.push_back(vec[i] - vec[i + 1]);
			if (vec[i] < vec[i + 1])vec2.push_back(vec[i + 1] - vec[i]);
		}
		vec = vec2;
	}
	cout << vec[0] << endl;
	return 0;
}