#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define int long long
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
int n,q,A[30],a[30],total;
void update(int x,int y){
	total-=(A[x]<<x);
	A[x]=y;
	total+=(A[x]<<x);
}
int query(int x,int k){
	if(k>total)return -1;
	int res=0,s=0,K=k;
	for(int i=0;i<n;i++)
		a[i]=A[i];
	for(int i=0;i<=x;i++)
		s+=(a[i]<<i),k-=a[i];
	if(k<=0)return 0;
	for(int i=x+1;i<n;i++){
		if(k>=(1<<(i-x))){
			int t=k/(1<<(i-x)),y=min(t,a[i]);
			k-=(y<<(i-x));
			res+=y*((1<<(i-x))-1);
			a[i]-=y,s-=(a[x]<<x),a[x]+=(y<<(i-x)),s+=(a[x]<<x);
		}
	}
	// cout<<"s"<<s<<endl;
	if(s>=K)return res+k;
	while(1){
		int l=0;
		for(int i=x+1;i<n;i++)
			if(a[i]){
				l=i;
				break;
			}
		// cout<<"t"<<t<<endl;
		for(int i=l;i>x;i--)
			a[i]--,a[i-1]+=2,res++;
		s+=(2ll<<x),k-=2;
		if(k<=0)return res;
		// cout<<"s"<<s<<endl;
		// cout<<"res"<<res<<endl;
		// cout<<"k"<<k<<endl;
		for(int i=x+1;i<n;i++){
			if(k>=(1<<(i-x))){
				int t=k/(1<<(i-x)),y=min(t,a[i]);
				k-=(y<<(i-x));
				res+=y*((1<<(i-x))-1);
				a[i]-=y,s-=(a[x]<<x),a[x]+=(y<<(i-x)),s+=(a[x]<<x);
			}
		}
		if(s>=K)return res+k;		
	}
}
signed main(){
	n=read(),q=read();
	for(int i=0;i<n;i++)
		A[i]=read(),total+=(A[i]<<i);
	int op,x,k;
	while(q--){
		op=read(),x=read(),k=read();
		if(op==1)update(x,k);
		else printf("%lld\n",query(x,k));
	}
	return 0;
}