#include <bits/stdc++.h>
using namespace std;
int main() {
  int m;
  cin >> m;
  int n = pow(2.0, m + 1) - 1;
  vector<int> v(n - 1);
  for (int i = 0; i < n - 1; i++) cin >> v[i];
  int lmax = 0;
  int s = pow(2.0, m) - 1;
  int t = pow(2.0, m + 1) - 1;
  vector<int> x;
  for (int i = s; i < t; i++) {
    int k = i;
    int cost = 0;
    while (k > 0) {
      cost += v[k - 1];
      k = (k - 1) / 2;
    }
    lmax = max(lmax, cost);
    x.push_back(cost);
  }
  bool check = true;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] != lmax) check = false;
  }
  if (check) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  int index = 0;
  while (true) {
    bool flag = true;
    v[index]++;
    x.clear();
    for (int i = s; i < t; i++) {
      int k = i;
      int cost = 0;
      while (k > 0) {
        cost += v[k - 1];
        k = (k - 1) / 2;
      }
      if (cost > lmax) {
        flag = false;
        break;
      }
      x.push_back(cost);
    }
    if (!flag) {
      v[index]--;
      index++;
    } else {
      ans++;
      bool ok = true;
      for (int i = 0; i < x.size(); i++)
        if (x[i] != lmax) ok = false;
      if (ok) break;
    }
  }
  cout << ans << endl;
  return 0;
}
