#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int N = 124;
int ko[N];
int n;
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i < n + 1; ++i) scanf("%d", &ko[i]);
    if (n == 1 || (n & 1) == 0) {
      puts("-1");
      continue;
    }
    int ans = 0;
    for (int i = (n - 1) / 2; i > 1; --i) {
      int res = max(ko[i * 2], ko[i * 2 + 1]);
      ans += res;
      ko[i * 2] = 0;
      ko[i * 2 + 1] = 0;
      ko[i] -= res;
      if (ko[i] < 0) ko[i] = 0;
    }
    ans += max(ko[1], max(ko[2], ko[3]));
    printf("%d\n", ans);
  }
  return 0;
}
