#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int a[309];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int ans = 0;
  if (n == 1 || n % 2 == 0)
    cout << -1 << endl;
  else {
    for (int i = n; i > 1; i -= 2) {
      int r = max(a[i], a[i - 1]);
      ans += r;
      a[i] = a[i - 1] = 0;
      a[i / 2] -= min(a[i / 2], r);
    }
    ans += a[1];
    cout << ans << endl;
  }
  return 0;
}
