#include <bits/stdc++.h>
using namespace std;
#define N 1010
#define ll long long
int n,q,x,y;
ll a[N],z;
ll work(int x,ll k){
	ll sum=0,res=0,tmp=0,ans=1e18;
	for(int i=0;i<=x;i++)
		sum+=a[i]*(1ll<<i)-a[i],tmp+=a[i];
	if(tmp>=k)	return 0;
	k-=tmp;int now=x+1;
	for(;now<n;now++){
		tmp=(1ll<<(now-x));ll need=min(a[now],k/tmp);
		k-=tmp*need;res+=need*(tmp-1);
		sum+=need*tmp*((1ll<<x)-1);
		if(need<a[now])	break;
	}
	if(k==0)	return res;
	if(now==n){
		if(sum>=k)	return res+k;
		return -1;
	}
	while(now>x){
		if(sum>=k)	ans=min(ans,res+k);
		res++;now--;
		tmp=(1ll<<(now-x));
		if(k>=tmp){
			res+=tmp-1;k-=tmp;sum+=tmp*(1ll<<x)-tmp;
		}
	}
	return min(res,ans);
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=q;i++){
		scanf("%d%d%lld",&x,&y,&z);
		if(x==1)
			a[y]=z;
		else
			printf("%lld\n",work(y,z));
	}
	return 0;
}