#include <bits/stdc++.h>
using namespace std;
const int mm = 1000 + 10;
int num[mm];
int n, ans, m;
int main() {
  while (cin >> n) {
    ans = 0;
    for (int i = 1; i <= n; i++) cin >> num[i];
    if (n % 2 == 0 || n == 1) {
      cout << "-1\n";
      continue;
    }
    for (int i = n; i >= 2; i--) {
      if (i & 1)
        m = (i - 1) / 2;
      else
        m = i / 2;
      while (num[i]) {
        num[i]--;
        if (num[m]) num[m]--;
        if (num[m + m] && (i & 1)) num[m + m]--;
        ans++;
      }
    }
    ans += num[1];
    cout << ans << "\n";
  }
}
