#include <bits/stdc++.h>
int a[150];
int n;
int max(int p, int q) { return p > q ? p : q; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  if (n < 3 || n % 2 == 0) {
    printf("-1");
    return 0;
  }
  int cur = n;
  int ans = 0;
  while (cur >= 1) {
    int div = max(a[cur], a[cur - 1]);
    ans += div;
    a[cur] = max(0, a[cur] - div);
    a[cur - 1] = max(0, a[cur - 1] - div);
    a[cur / 2] = max(0, a[cur / 2] - div);
    cur -= 2;
  }
  printf("%d", ans);
  return 0;
}
