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