#include<cstdio>
#define int ll
typedef long long ll;
int n,a[35];
inline int read() {
	register int x=0,f=1;register char s=getchar();
	while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
	return x*f;
}
inline int min(const int &x,const int &y) {return x<y? x:y;}
inline int solve(int x,int k) {
	int enable_sum=0,big_sum=0,res=0,tmp=0,ans=1e15;
	for(register int i=0;i<=x;++i) {enable_sum+=a[i]*((1ll<<i)-1); tmp+=a[i];}
	if(tmp>=k) return 0; //tmp<k \to k>tmp
	k-=tmp; int cur=x+1;
	while(cur<n) {
		tmp=(1ll<<(cur-x)); int need=min(k/tmp,a[cur]); 
		k-=need*tmp; res+=need*(tmp-1); enable_sum+=need*tmp*((1ll<<x)-1);
		if(need<a[cur]) {break;}
		++cur;
	} 
	if(k==0) return res;
	if(cur==n) {
		if(enable_sum>=k) return res+k;
		else return -1;
	}
	//选到某一个 cur 停下来不选，因为可能不优，然后现在考虑把这个 2^cur 分掉 
	while(cur>x) {
		if(enable_sum>=k) {ans=min(ans,res+k);}
		++res; --cur; //Warning
		tmp=(1ll<<(cur-x));
		if(k>=tmp) {res+=tmp-1; k-=tmp; enable_sum+=tmp*((1ll<<x)-1);}
	}  
	return min(res,ans); 
}
signed main() {
	n=read(); int Q=read();
	for(register int i=0;i<n;++i) a[i]=read();  
	while(Q--) {
		int op=read(),x=read(),y=read();
		if(op==1) {a[x]=y;}
		else {printf("%lld\n",solve(x,y));}
	}
	return 0;
} 