#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
	int i, n, j, vertex = 1, sum = 1, flag=0;
	int a[25];
	scanf("%d", &n);
	for (i = 0; i <= n; i++)
	{
		scanf("%d", &j);
		a[i] = j;
	}

	for (i = 0; i < n; i++) {
		if ((vertex - a[i]) >= 0) {
			vertex = 2 * (vertex - a[i]);
			sum += vertex;
		}
		else {
			printf("%d", -1);
			flag = 1;
			break;
		}
	}
	if(flag==0)
		printf("%d", sum);
	
	return 0;
}