#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  if (N <= 2 || N % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  vector<int> box(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> box[i];
  }
  for (int i = N; i >= 2; i--) {
    if (i & 1) {
      while (box[i]) {
        int x = (i - 1) / 2;
        box[i]--;
        box[x] -= box[x] ? 1 : 0;
        box[2 * x] -= box[2 * x] ? 1 : 0;
        ans++;
      }
    } else {
      while (box[i]) {
        int x = i / 2;
        box[i]--;
        box[x] -= box[x] ? 1 : 0;
        box[2 * x + 1] -= box[2 * x + 1] ? 1 : 0;
        ans++;
      }
    }
  }
  ans += box[1];
  cout << ans << endl;
  return 0;
}
