#include <bits/stdc++.h>
using namespace std;
const int N = 102;
vector<int> p[N];
int a[N];
int main() {
  int n, pos = 1, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n % 2 == 0 || n == 1) {
    cout << -1;
    return 0;
  }
  for (int i = n; i >= 3; i -= 2) {
    p[pos].push_back(i);
    p[pos].push_back(i - 1);
    p[pos].push_back((i - 1) / 2);
    pos++;
  }
  for (int i = 1; i < pos; i++) {
    ans += max(a[p[i][0]], a[p[i][1]]);
    if (a[p[i][2]] <= max(a[p[i][0]], a[p[i][1]]))
      a[p[i][2]] = 0;
    else
      a[p[i][2]] -= max(a[p[i][0]], a[p[i][1]]);
    a[p[i][0]] = 0;
    a[p[i][1]] = 0;
  }
  if (a[1] != 0) ans += a[1], a[1] = 0;
  cout << ans;
}
