#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vec vector
#define psb push_back
#define ppb pop_back
#define psf push_front
#define ppf pop_front
#define ins insert
#define fst first
#define scd second
using namespace std;
inline void solve() {
	ll n, q;
	cin >> n >> q;
	ll cnt[n];
	for(ll i = 0; i < n; i++) {
		cin >> cnt[i];
	}
	for (ll qs = 0; qs < q; qs++) {
		ll tp, pos;
		ll val;
		cin >> tp >> pos >> val;
		if (tp == 1) {
			cnt[pos] = val;
		}
		else {
			ll small = 0, cur = 0;
			for (ll i = 0; i < pos + 1; i++) {
				small += cnt[i] * ((1ll << i) - 1);
				val -= cnt[i];
			}
			if (val <= 0) {
				cout << 0 << '\n';
				continue;
			}
			
			int id = pos + 1;
			while (id < n) {
				ll add = 1ll << (id - pos);
				ll need = min(val / add, cnt[id]);
				cur += need * (add - 1);
				val -= need * add;
				small += need * add * ((1ll << pos) - 1);
				
				if (need == cnt[id])
					id++;
				else
					break;
			}
			if (val <= 0) {
				cout << cur << '\n';
				continue;
			}
			if (id >= n) {
				cout << (val > small ? -1 : cur + val) << '\n';
				continue;
			}
			
			ll ans = numeric_limits<ll> :: max();
			while (id > pos) {
				if (small >= val)
					ans = min(ans, cur + val);
				cur++;
				id--;
				ll add = 1ll << (id - pos);
				if (val >= add) {
					cur += add - 1;
					val -= add;
					small += add * ((1ll << pos) - 1);
				}
			}
			cout << min(ans, cur) << '\n';
		}
	}
}

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	solve();
	return 0;
}
