#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 100 + 5;
int n, a[N], ans;
int main() {
  ios ::sync_with_stdio(0);
  cin >> n;
  if (!(n & 1) or n == 1) {
    cout << -1 << '\n';
    return 0;
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n - 1 >> 1; i >= 1; i--) {
    int mx = max(a[i * 2], a[i * 2 + 1]);
    if (mx <= 0) continue;
    a[i] -= mx;
    a[i * 2] -= mx;
    a[i * 2 + 1] -= mx;
    ans += mx;
  }
  cout << ans + (a[1] > 0 ? a[1] : 0) << '\n';
  cerr << "Tooks " << (double)clock() / CLOCKS_PER_SEC << " seconds." << '\n';
  return 0;
}
