#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int n, a[maxn], s;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n <= 2 || n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = (n - 1) / 2; i >= 1; i--) {
    if (i == 1) {
      a[1] = max(a[1], a[2]);
      a[1] = max(a[1], a[3]);
      s += a[1];
    } else if (max(a[i * 2], a[i * 2 + 1]) > 0) {
      s += max(a[i * 2], a[i * 2 + 1]);
      a[i] -= max(a[i * 2], a[i * 2 + 1]);
    }
  }
  cout << s << endl;
  return 0;
}
