#include <bits/stdc++.h>
using namespace std;
int n, lis[111], ans;
int main() {
  cin >> n;
  for (int i = 1; i < 1 + n; i++) cin >> lis[i];
  ans = 0;
  if (n % 2 == 0 || n == 1) {
    cout << -1;
    return 0;
  }
  for (int i = n; i > 1; i -= 2) {
    ans += max(lis[i], lis[i - 1]);
    lis[i / 2] = max(0, lis[i / 2] - max(lis[i], lis[i - 1]));
  }
  ans += lis[1];
  cout << ans;
}
