#include <bits/stdc++.h>

using namespace std;

template<typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; }
template<typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; }

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int, int> PR;
typedef vector<int> VI; 

const lod eps = 1e-9;
const lod pi = acos(-1);
const int oo = 1 << 30;
const ll loo = 1ll << 60;
const int mods = 998244353;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f; //1061109567
/*--------------------------------------------------------------------*/
namespace FastIO{
	constexpr int SIZE = (1 << 24) + 1;
	int num = 0, f;
	char ibuf[SIZE], obuf[SIZE], que[65], *iS, *iT, *oS = obuf, *oT = obuf + SIZE - 1, c;
	#define gc() (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush() {
		fwrite(obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	inline void putc(char c) {
		*oS ++ = c;
		if (oS == oT) flush();
	}
	inline void getc(char &c) {
		for (c = gc(); (c != '*' && c != '-' && c != '+') && c != EOF; c = gc());
	}
	inline int reads(char *st) {
		char c;
		int n = 0;
		getc(st[++ n]);
		for (c = gc(); c == '*' || c == '-' || c == '+' ; c = gc()) st[++ n] = c;
		return n;
	}
	template<class I>
	inline void read(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9' ; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9' ; c = gc()) x = (x << 3) + (x << 1) + (c & 15);
		x *= f;
	}
	template<class I>
	inline void print(I x) {
		if (x < 0) putc('-'), x = -x;
		if (!x) putc('0');
		while (x) que[++ num] = x % 10 + 48, x /= 10;
		while (num) putc(que[num --]);
	}
	struct Flusher_{~Flusher_(){flush();}} io_Flusher_;
}
using FastIO :: read;
using FastIO :: putc;
using FastIO :: reads;
using FastIO :: print;

ll a[35], b[35];
void query(int n, ll t, ll y) {
	for (int i = 0; i < n ; ++ i) b[i] = a[i];

	ll ans = 0, all = 0, ALL = 0;
	for (int i = 0; i <= t ; ++ i) all += b[i] * ((1 << i) - 1), ALL += b[i] * ((1 << i) - 1), y -= b[i];
	for (int i = t + 1; i <= n ; ++ i) ALL += b[i] * (1 << i);
	if (ALL < y) { print(-1), putc('\n'); return; }
	if (y < 0) { print(0), putc('\n'); return; }
	
	while (1) {
		int flag = 0;
		for (int i = t + 1 ; i < n ; ++ i)
			if (b[i]) {
				flag = 1;
				ll p = (1 << (i - t));
				ll q = min(y / p, b[i]);
				b[i] -= q, y -= q * p, ans += q * (p - 1), all += q * p * ((1 << t) - 1);
//				cout << y << " " << b[i] << " " << p << " " << ans << " " << all << endl;
				if (b[i]) {
					if (all >= y) { print(ans + y), putc('\n'); return; }
					for (int j = t + 1; j < i ; ++ j) ++ b[j];
					-- b[i], ans += (i - t), y -= 2, all += ((1 << t) - 1) * 2;
					break;
				}			
			}
		if (!flag) { print(ans + y), putc('\n'); return; }
		if (y <= 0) { print(ans), putc('\n'); return; }
	}
	print(ans), putc('\n');
}
signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
#endif
	int n, Case;
	read(n), read(Case);
	for (int i = 0; i < n ; ++ i) read(a[i]);
	for (; Case -- ;) {
		ll opt, x, y; 
		read(opt), read(x), read(y);
		if (opt == 1) a[x] = y;
		else query(n, x, y);
	}
	return 0;
}