#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int maxn = 4e5	+5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;

LL cnt[30],tmp[30];
LL tmp2[30];
LL calc(int now,int x,LL need){
	if(need==0) return 0;
	if(now==x+1) return 1;
	if(x!=0){
		for(int i=0;i<=x;i++) tmp2[i]=tmp[i];
		LL need2 = need;
		LL ret2 = 0;
		for(int i=x;i>0;i--){
			LL num = min(need2,tmp2[i]);
			ret2 += num;
			tmp2[i-1] += 2*num;
			need2 -= num;
			if(need2<=0) break;
		}
		if(need2<=0) return ret2;
		else{
			if(need>= (1<<(now-x-1))){
				tmp[x] += (1<<(now-x-1));
				return (1<<(now-x-1))+calc(now-1,x,need-(1<<(now-x-1)));
			}
			else{
				return 1+calc(now-1,x,need);
			}
		}

	}
	else{
		if(need>= (1<<(now-x-1))){
			tmp[x] += (1<<(now-x-1));
			return (1<<(now-x-1))+calc(now-1,x,need-(1<<(now-x-1)));
		}
		else{
			return 1+calc(now-1,x,need);
		}
	}
}

int main(void)
{
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++)
		scanf("%lld",cnt+i);
	while(q--){
		int op;
		scanf("%d",&op);
		if(op==1){
			int pos,val;
			scanf("%d%d",&pos,&val);
			cnt[pos]=val;
		}
		else{
			int x;
			LL need;
			scanf("%d%lld",&x,&need);
			for(int i=0;i<=x;i++)
				need-=cnt[i];
			if(need<=0) printf("0\n");
			else{
				memcpy(tmp,cnt,sizeof cnt);
				LL ans=0;
				int flag=1;
				for(int i=x+1;i<n;i++){
					LL per = 1<<(i-x);
					LL num = min(1ll*tmp[i],need/per);
					need -= num*per;
					ans += num*(per-1);
					tmp[i]-=num;
					tmp[x]+=num*per;
					if(tmp[i]>0 || need==0){
						ans += calc(i,x,need);
						flag=0;
						break;
					}
				}
				if(flag==0) printf("%lld\n", ans);
				else{
					for(int i=x;i>0;i--){
						LL num = min(need,tmp[i]);
						ans += num;
						tmp[i-1] += 2*num;
						need -= num;
						if(need<=0) break;
					}
					if(need<=0) printf("%lld\n", ans);
					else printf("-1\n");
				}
			}
		}
	}
}
