#include <bits/stdc++.h>
using namespace std;
int n, i, j, ans, a[10000];
int main() {
  cin >> n;
  if (n < 3 || n % 2 == 0) {
    cout << -1;
    return 0;
  }
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = n; i >= 1; i--)
    if (a[i] > 0) {
      ans += a[i];
      if (i % 2 == 0)
        a[i / 2] -= a[i];
      else {
        if (i - 1 >= 1) a[i - 1] -= a[i];
        if (i - 1 >= 1) a[(i - 1) / 2] -= a[i];
      }
    }
  cout << ans << endl;
}
