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