#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main(){
	ll n,q;
	ll a[32], v[32]; v[0] = 1;
	scanf("%lld%lld",&n,&q);
    for (int i = 1; i < n; ++i) v[i] = v[i - 1] << 1;
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(;q>0;q--){
		ll t,x,k;
		scanf("%lld%lld%lld",&t,&x,&k);
		if(t==1){
			a[x]=k;
		}
		else {
			ll b[32];
			for(int i=0;i<n;i++)b[i]=a[i];
			ll ret=0, sum = 0, cnt=0;
			for(int i=0;i<=x;i++)cnt+=b[i], sum += v[i] * b[i];
			while(1){
				if(cnt>=k)break;
				for(int i=x+1;i<n;i++){
					ll s=min(b[i],(k-cnt)/v[i - x]), cs = s * v[i - x];
					ret+=cs - s;
					cnt+=cs;
					b[i]-=s;
					b[x]+=cs; sum += cs * v[x];
				}
				if(sum>=k){
					ret+=k-cnt;
					break;
				}
				int loc=x+1;
				while(loc<n&&b[loc]==0)loc++;
				if(loc==n){
					ret=-1;
					break;
				}
				ret+=loc-x;
				cnt+=2;
				b[x]+=2; sum += v[x + 1];
				for(int i=x+1;i<loc;i++)b[i]++;
			}
			printf("%lld\n",ret);
		}
	}
}	