#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
int a[105];
int main() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (int)(n); (i)++) scanf("%d", a + i + 1);
  if (n % 2 == 0 && a[n]) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  int x = (n - 1) / 2;
  if (x == 0) {
    puts("-1");
    return 0;
  }
  for (int i = x; i; i--) {
    int y = max(a[i + i], a[i + i + 1]);
    ans += y;
    a[i] -= min(a[i], y);
  }
  if (a[1] != 0) ans += a[1];
  printf("%d\n", ans);
  return 0;
}
