#include <bits/stdc++.h>
using namespace std;
int n, a[1000];
void readdata() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
}
int work(int p) {
  if (p == 3) return max(max(max(a[1], a[2]), a[3]), 0);
  int t = max(a[p], a[p - 1]);
  a[(p - 1) >> 1] -= t;
  if (a[(p - 1) >> 1] < 0) a[(p - 1) >> 1] = 0;
  return t + work(p - 2);
}
int main() {
  readdata();
  if (n % 2 == 0 || n < 3)
    cout << "-1" << endl;
  else
    cout << work(n) << endl;
  return 0;
}
