#include <bits/stdc++.h>
const int maxn = 105;
int a[maxn];
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n, ans = 0, temp;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  if (n < 3 || n % 2 == 0)
    puts("-1");
  else {
    for (int i = (n - 1); i >= 1; i -= 2) {
      temp = max(a[i], a[i + 1]);
      ans += temp;
      a[i / 2] -= temp;
      if (a[i / 2] < 0) a[i / 2] = 0;
    }
    ans += a[1];
    printf("%d\n", ans);
  }
  return 0;
}
