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