#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+5;
ll qpow(ll a,ll n){
	ll re=1;
	while(n>0){
		if(n&1){
			re*=a;
		}
		a*=a;
		n>>=1;
	}
	return re;
}
ll p[N],cnt[N],sum[N];
int main()
{
	ll n,q;
	scanf("%lld%lld",&n,&q);
	for(int i=0;i<n;i++){
		p[i]=pow(2,i);
	}
	for(int i=0;i<n;i++){
		scanf("%lld",&cnt[i]);
		sum[i]=cnt[i]*p[i];
	}
	while(q--){
		ll op;
		scanf("%lld",&op);
		if(op==1){
			ll pos,val;
			scanf("%lld%lld",&pos,&val);
			cnt[pos]=val;
			sum[pos]=cnt[pos]*p[pos];
		}
		else if(op==2){
			ll x,k;
			scanf("%lld%lld",&x,&k);
			ll tot=0;
			for(int i=0;i<n;i++){
				tot+=sum[i];
			}
			if(tot<k){
				printf("-1\n");
				continue;
			}
			
			ll tot1=0,tot2=0;
			for(int i=0;i<=x;i++){
				tot1+=cnt[i],tot2+=sum[i];
			}
			if(tot1>=k){
				printf("0\n");
				continue;
			}
			
			ll ans=0; 
			for(int i=x+1;i<n;i++){
				ll re=min((k-tot1)/(p[i]/p[x]),cnt[i]);
				tot1+=re*p[i]/p[x];
				tot2+=re*p[i];
				ans+=re*(p[i]/p[x]-1);
				if(re<cnt[i]){
					for(int j=i-1;j>=x;j--){
						if(tot2>=k) break;
						ans++; 
						if(tot1+p[j]/p[x]<=k){
							tot1+=p[j]/p[x];
							tot2+=p[j];
							ans+=p[j]/p[x]-1;
						}
					}
					break;
				}
			}
			if(tot2>=k){
				printf("%lld\n",ans+k-tot1);
			}
			
		}
	}
}
/*
6 100
0 0 0 0 1 1
*/

