#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int treeSize(int x) {
        

        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}



int main() {
    long long N;
    cin >> N;

    long long dummy;
    cin >> dummy;

    if (dummy != 0 && N != 0) {
        cout << -1 << endl;
        return 0;
    }
    else if (N == 0 && dummy == 1) {
        cout << 1 << endl;
        return 0;
    }

    long long  totalCount = 0;
    long long  childHavableNodes = 1;
    long long  totalNodes = 1;

    vector<long long> A(N);
    long long totalLeaves = 0;
    for (int i = 0; i < N; i++) {
        long long temp;
        cin >> temp;

        A[i] = temp;
        totalLeaves += A[i];
    }

    if (totalLeaves == 0) {
        cout << -1 << endl;
        return 0;
    }

    for (long long i = 0; i < N; i++) {
        totalLeaves -= A[i];
        if (A[i] > childHavableNodes * 2) {
            cout << -1 << endl;
            return 0;
        }
        else {
            totalNodes += A[i];

            if ((childHavableNodes * 2 - A[i]) > totalLeaves) {
                childHavableNodes = totalLeaves;
            }
            else {
                childHavableNodes = childHavableNodes * 2 - A[i];
            }

            if (i != N - 1) {
                totalNodes += childHavableNodes;
            }
            //cout << totalNodes << endl;
        }
    }
    
    cout << totalNodes << endl;
    /*int N;
    cin >> N;
    UnionFind unionFind = UnionFind(N + 1);

    int totalCount = 0;
    vector<int> negativeNodes;
    for (int i = 1; i < N + 1; i++) {
        int temp;
        cin >> temp;

        if (temp != -1 && unionFind.unite(i, temp)) {
            totalCount++;
        }
        else if (temp == -1) {
            negativeNodes.push_back(i);
        }
    }*/


    return 0;
}

Measured memory_bytes: 4052