#include <bits/stdc++.h>
using namespace std;
int n;
int a[111];
int main() {
  scanf("%d", &n);
  if (n <= 2 || n % 2 == 0) return puts("-1"), 0;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  int counter = 0;
  for (int i = n; i > 1; i -= 2) {
    int delta = max(a[i], a[i - 1]);
    counter += delta;
    a[i] = max(0, a[i] - delta);
    a[i - 1] = max(0, a[i - 1] - delta);
    a[i / 2] = max(0, a[i / 2] - delta);
  }
  cout << counter + a[1] << endl;
}
