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