#include <bits/stdc++.h>
using namespace std;
int n;
int a[100];
int total = 0;
int main() {
  scanf("%d", &n);
  if (n == 1 || n % 2 == 0) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i > 0; i -= 2) {
    total += max(a[i], a[i - 1]);
    a[i / 2 - 1] = max(0, a[i / 2 - 1] - max(a[i], a[i - 1]));
  }
  printf("%d\n", total + a[0]);
  fflush(stdin);
  getchar();
}
