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