/*
This is code of SuperJ6 for Codeforces.
Don't copy my code during f*kin' contests.

2.71828182845904523536
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 30;
int n, q;
ll a[mxn];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> q;
	
	for(int i = 0; i < n; i++) cin >> a[i];
	
	while(q--){
		ll t, x, y;
		cin >> t >> x >> y;
		if(t & 1){
			a[x] = y;
		}else{
			ll c = 0, s = 0, i;
			for(i = 0; i <= x; i++) y -= a[i], s += a[i] * ((1 << i) - 1);
			
			if(y <= 0){
				cout << 0 << endl;
				continue;
			}
			
			for(; i < n; i++){
				ll f = 1 << (i - x), d = min(a[i], y / f);
				c += d * (f - 1), y -= d * f, s += d * f * ((1 << x) - 1);
				if(d < a[i]) break;
			}
			
			if(i == n){
				cout << (y <= s ? c + y : -1) << endl;
				continue;
			}
			
			ll ret = 0x3f3f3f3f3f3f3f3f;
			for(; i > x; i--){
				if(s >= y) ret = min(ret, c + y);
				c++;
				ll f = 1 << (i - x - 1);
				if(y >= f) c += f - 1, y -= f, s += f * ((1 << x) - 1);
			}
			ret = min(ret, c);
			
			cout << ret << endl;
		}
	}

	return 0;
}