#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1 << 8;
int N, A[MaxN];
int main(void) {
  cin.sync_with_stdio(0);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> A[i];
  if (N < 3) {
    bool Found = false;
    for (int i = 1; i <= N; i++)
      if (A[i]) Found = true;
    if (Found)
      cout << -1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  if ((!(N % 2)) && (A[N])) {
    cout << -1 << endl;
    return 0;
  }
  int Sol = A[1];
  A[1] = A[1];
  A[2] -= A[1];
  A[3] -= A[1];
  for (int i = N; i >= 2; i--) {
    if (A[i] <= 0) continue;
    Sol += A[i];
    if (i % 2) {
      A[(i - 1) / 2] -= A[i];
      A[i - 1] -= A[i];
    } else
      A[i / 2] -= A[i];
  }
  cout << Sol << endl;
  return 0;
}
