#include <bits/stdc++.h>
using namespace std;
int n;
int a[1024];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n == 1 || n % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int res = 0;
  int mx;
  for (int i = n; i >= 3; i -= 2) {
    mx = max(a[i], a[i - 1]);
    res += mx;
    a[i] = a[i - 1] = 0;
    a[(i - 1) / 2] -= mx;
    if (a[(i - 1) / 2] < 0) a[(i - 1) / 2] = 0;
  }
  res += a[1];
  cout << res << endl;
  return 0;
}
