#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  int moves = 0;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  if (n % 2 == 0 || n == 1)
    cout << "-1" << endl;
  else {
    for (int i = n; i >= 1; i = i - 2) {
      if (i == 1) {
        moves = moves + arr[i];
        break;
      }
      int sub = max(arr[i], arr[i - 1]);
      moves = moves + sub;
      if (arr[(i - 1) / 2] <= sub) {
        arr[(i - 1) / 2] = 0;
      } else {
        arr[(i - 1) / 2] -= sub;
      }
    }
    cout << moves << endl;
  }
  return 0;
}
