#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e2 + 5;
int arr[MAX];
int n;
int main() {
  scanf("%d", &n);
  if (n == 1 || (n % 2 == 0)) {
    puts("-1");
    return 0;
  }
  for (int i = int(1); i < int(n + 1); i++) {
    scanf("%d", arr + i);
  }
  int ans = 0;
  int upto = n / 2;
  for (int i = int(upto); i >= int(2); i--) {
    int mx = max(arr[2 * i], arr[2 * i + 1]);
    arr[i] = max(0, arr[i] - mx);
    arr[2 * i] = 0;
    arr[2 * i + 1] = 0;
    ans += mx;
  }
  ans += max({arr[1], arr[2], arr[3]});
  printf("%d\n", ans);
  return 0;
}
