#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  int arr[1002];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = n / 2; i >= 0; i--) {
    int x = max(arr[i * 2], arr[i * 2 + 1]);
    ans += x;
    arr[i * 2] = 0;
    arr[i * 2 + 1] = 0;
    arr[i] = max(0, arr[i] - x);
  }
  cout << ((n == 1 || n % 2 == 0) ? -1 : ans) << endl;
  return 0;
}
