#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>

typedef long long ll;

int n, q;
std::vector<ll> a;

void query(ll x, ll k) {
	std::vector<ll> vals = a;
	ll tot = 0;
	ll ans = 0;
	ll add = 0;
	
	for (int i = 0; i <= x; i++) {
		ll gainPer = 1 << i;
		tot += vals[i];
		add += (gainPer - 1) * vals[i];
	}
	
	int revStart = n - 1;
	for (int i = x + 1; i < n && tot < k; i++) {
		ll gp = 1 << (i - x);
		ll take = std::min(vals[i], (k - tot + 1) / gp);
		vals[i] -= take;
		vals[x] += take * gp;
		ans += take * (gp - 1);
		tot += take * gp;
		add += take * gp * ((1 << x) - 1);
		if (vals[i] > 0) {
			revStart = i;
			break;
		}
	}
	
	if (tot + add < k) {
		for (int i = revStart; i > x; i--) {
			ll gp = 1 << (i - x);
			ll take = std::min(vals[i], (k - tot + 1) / gp);
			vals[i] -= take;
			vals[x] += take * gp;
			ans += take * (gp - 1);
			tot += take * gp;
			add += take * gp * ((1 << x) - 1);
			
			if (tot + add < k) {
				ll gainPer = 1 << i;
				take = std::min(vals[i], (k - tot - add + gainPer - 1) / gainPer);
				vals[i] -= take;
				vals[i - 1] += take * 2;
				ans += take;
			}
		}
	}
	
	if (tot + add < k) {
		printf("-1\n");
		return;
	}
	
	if (tot < k) {
		ans += k - tot;
	}
	
	printf("%lld\n", ans);
}

int main() {
	scanf("%d %d", &n, &q);
	a.resize(n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < q; i++) {
		ll t, v1, v2;
		scanf("%lld %lld %lld", &t, &v1, &v2);
		if (t == 1) {
			a[v1] = v2;
		}
		else if (t == 2) {
			query(v1, v2);
		}
	}

	return 0;
}
