#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    int n; cin >> n;
    vector<ll> a(n+1);
    ll sum=0;
    cin >> a[0];
    for (int i=1; i<=n; ++i) {
        cin >> a[i];
        sum+=a[i];
    }
    if (a[n]==0) {
        cout << -1 << endl;
        return 0;
    }
    ll ans=0, cur=1;
    for (int i=0; i<=n; ++i) {
        sum-=a[i];
        ans+=cur;
        if (cur<a[i]) {
            cout << -1 << endl;
            return 0;
        }
        cur=min(cur*2-a[i]*2, sum);
    }
    cout << ans;
    return 0;
}