#include <bits/stdc++.h>
using namespace std;
const int MAX = 2100000000;
int a[110];
int main() {
  int n;
  int ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n % 2 == 0 || n <= 2)
    cout << -1 << endl;
  else {
    for (int i = n; i > 0; i--) {
      if (a[i] > 0) {
        int t = a[i];
        ans += t;
        if (i % 2) {
          a[i - 1] -= t;
        }
        a[i / 2] -= t;
      }
    }
    cout << ans << endl;
  }
}
