#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 1000000010

int frq[40];

int n , q;


int main(){
	scanf("%d%d",&n,&q);
	for(int i = 0 ;i < n;i++){
		scanf("%d",&frq[i]);
	}
	int t , x , idx;
	long long k , tmp , need , ans , mx , has , cur , inc;
	while(q--){
		scanf("%d",&t);
		if(t == 1){
			scanf("%d%d",&idx,&x);
			frq[idx] = x;
		}
		else{
			scanf("%d%lld",&x,&k);
			ans = (long long)1e18 , cur = 0 , mx = 0 , has = 0;
			for(int i = 0 ;i <= x;i++){
				has += frq[i];
				mx += (long long)frq[i] * (1LL << i);
			}
			if(mx >= k)
				ans = max(0LL , k - has);
			for(int i = x + 1;i < n && k > has;i++){
				tmp = (k - has) / (1LL << (i - x));
				tmp = min(tmp , (long long)frq[i]);


				cur += (long long)tmp * ((1LL << (i - x)) - 1);
				has += (long long)tmp * (1LL << (i - x));
				mx += (long long)tmp * (1LL << i);

				if(mx >= k){
					ans = min(ans , max(0LL , k - has) + cur);
				}
				if(tmp < (long long)frq[i]){
					tmp = 1;
					for(int j = i ; j > x;j--){
						if(tmp == 1){
							ans = min(ans , cur + (1LL << (j - x)) - 1);
							cur++;
							tmp = 2;
							continue;
						}
						else{
							if(has + (1LL << (j - x)) <= k){
								cur += (1LL << (j - x)) - 1;
								has += (1LL << (j - x));
								mx += (1LL << j);
								if(mx >= k){
									ans = min(ans , max(0LL , k - has) + cur);
								}
							}
							ans = min(ans , cur + (1LL << (j - x)) - 1);
							cur++;
							tmp = 2;
						}
					}
					assert(has + tmp >= k);
					ans = min(ans , cur);
					break;
				}
			}
			if(ans == (long long)1e18)
				ans = -1;
			printf("%lld\n",ans);
			
		}
	}
	
	return 0;
}