#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[111];
  while (~scanf("%d", &n)) {
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    if (n <= 2 || n % 2 == 0) {
      printf("-1\n");
      continue;
    }
    int ans = 0, cnt;
    for (int i = n; i >= 1; i -= 2) {
      if (a[i] >= 0 || a[i - 1] >= 0) {
        cnt = max(a[i], a[i - 1]);
        ans += cnt;
        a[i] -= cnt;
        a[i - 1] -= cnt;
        a[(i - 1) / 2] -= cnt;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
