#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i = (1); i < (n + 1); i++) cin >> v[i];
  if (n % 2 == 0) {
    while (((int)(v).size()) > 1 && v.back() == 0) v.pop_back();
  }
  if ((((int)(v).size()) - 1) < 3 || (((int)(v).size()) - 1) % 2 == 0) {
    cout << -1;
    return 0;
  }
  int re = 0;
  for (int i = n; i > 0; i--) {
    if (i % 2 == 0) continue;
    int tmp = max(v[i], v[i - 1]);
    re += tmp;
    v[i - 1] = v[i] = 0;
    v[i / 2] = max(0, v[i / 2] - tmp);
  }
  cout << re;
  return 0;
}
