#include <bits/stdc++.h>
using namespace std;
int a[1000] = {}, ans;
bool vis[1000], mark[1000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if ((n == 1 || n == 2)) {
    if (*min_element(a + 1, a + n + 1)) {
      cout << -1;
      return 0;
    }
    cout << 0;
    return 0;
  }
  if (!(n % 2) && a[n]) {
    cout << -1 << endl;
    return 0;
  }
  ans = a[1];
  a[2] = max(a[2] - a[1], 0);
  a[3] = max(a[3] - a[1], 0);
  a[1] = 0;
  for (int i = n; i > 1; i--) {
    a[i / 2] = max(a[i / 2] - a[i], 0);
    if (i % 2) a[i - 1] = max(a[i - 1] - a[i], 0);
    ans += a[i];
    a[i] = 0;
  }
  cout << ans << endl;
}
