#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int arr[MAXN];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  if (n % 2 == 0 || n == 1) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = n; i > 1; i--) {
    while (arr[i] > 0) {
      ans++;
      arr[(i / 2) * 2]--;
      arr[(i / 2) * 2 + 1]--;
      arr[i / 2]--;
    }
  }
  if (arr[1] > 0) ans += arr[1];
  cout << ans << endl;
  return 0;
}
