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