#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<climits>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=35;
int n,q,op,x;
ll y,sum,cur,minn,ans,cnt[N],tmp[N];
int main(){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		scanf("%lld",&cnt[i]);
	}
	while(q--){
		scanf("%d%d%lld",&op,&x,&y);
		if(op==1){
			cnt[x]=y;
		}else{
			sum=0;
			for(int i=0;i<n;i++){
				tmp[i]=cnt[i];
				sum+=tmp[i]*(1<<i);
			}
			if(sum<y){
				puts("-1");
				continue;
			}
			sum=cur=0;
			for(int i=0;i<=x;i++){
				sum+=tmp[i]*(1<<i);
				cur+=tmp[i];
			}
			if(cur>=y){
				puts("0");
				continue;
			}
			y-=cur;
			sum-=cur;
			ans=0;
			for(int i=x+1;i<n;i++){
				ll t=min(tmp[i],y/(1<<(i-x)));
				tmp[i]-=t;
				ans+=t*((1<<(i-x))-1);
				y-=t*(1<<(i-x));
				tmp[x]+=t*(1<<(i-x));
				t*=1<<(i-x);
				if(x){
					sum+=t*((1<<x)-1);
				}
			}
			int pos=x;
			for(int i=x+1;i<n;i++){
				if(tmp[i]&&y/(1<<(i-x))==0){
					pos=i;
					break;
				}
			}
			minn=y<=sum?ans+y:LLONG_MAX;
			for(int i=pos;i>x;i--){
				if(y/(1<<(i-x-1))==0){
					ans++;
				}else{
					ans+=1<<(i-x-1);
					y-=1<<(i-x-1);
					ll t=1<<(i-x-1);
					if(x){
						sum+=t*((1<<x)-1);
					}
				}
				if(y<=sum){
					minn=min(minn,ans+y);
				}
			}
			printf("%lld\n",minn);
		}
	}
	return 0;
}