#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N;

int main(){
	cin >> N;

	vector<long long> cur;
	vector<long long> next;

	for(int i = 0; i < pow(2, N); i++){
		long long tmp;
		cin >> tmp;
		cur.push_back(tmp);
	}

	while(true){
		if(cur.size() == 1){
			cout << cur[0] << endl;
			return 0;
		}
		for(int i = 0; i < cur.size(); i+=2){
			if(cur[i] < cur[i+1]){
				next.push_back(cur[i+1] - cur[i]);
			}else if(cur[i] > cur[i+1]){
				next.push_back(cur[i] - cur[i+1]);
			}else{
				next.push_back(cur[i]);
			}
		}
		swap(next, cur);
		next.clear();
	}





}

