#include <bits/stdc++.h>
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 200005;
using namespace std;
void solve() {
  int n, ans = 0, k;
  cin >> n;
  vector<int> a(n + 1);
  a[0] = 0;
  for (int i = 1; i < n + 1; i += 1) cin >> a[i];
  if ((n == 1) || (n & 1 ^ 1)) {
    cout << -1 << "\n";
    return;
  }
  for (int i = n; i > 0; i -= 2) {
    k = max(a[i], a[i - 1]);
    ans += k;
    a[i] = a[i - 1] = 0;
    a[i / 2] = max(0, a[i / 2] - k);
  }
  cout << ans;
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
