#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;

#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define pb push_back
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define mk make_pair
#define F first
#define S second
#define debug(a) cout << #a << " = " << a << endl;
#define int long long

const int INF = 1000000009;
const ll MOD = 1000000007LL;

int n, q;
int cnt[31], f[31];

vector<int> v;
int step, x, sml;

inline void Solve(int i, int &k) {
	int res = min(v[i], k / f[i - x]);
	k -= res * f[i - x];
	step += (f[i - x] - 1) * res;
	sml += (f[x] - 1) * res * f[i - x];
	v[i] -= res;

	if (v[i] == 0 && k > 0 && i + 1 < n) Solve(i + 1, k);
	else if (v[i] > 0) {
		if (sml >= k) {
			step += k;
			k = 0;
			return;
		}
		
		v[i] -= 1;
		v[i - 1] += 2;
		step += 1;
		if (i - 1 == x) {
			k = 0;
			return;
		}
		Solve(i - 1, k);
	}
	
	
}

signed main() { IOS
	f[0] = 1;
	for (int i = 1; i <= 30; ++ i) f[i] = f[i - 1] * 2;

	cin >> n >> q;
	for (int i = 0; i < n; ++ i) cin >> cnt[i];
	
	while ( q -- ) {
		int op; cin >> op;
		
		if (op == 1) {
			int pos, val;
			cin >> pos >> val;
			cnt[pos] = val;
		}
		else {
			int k;
			cin >> x >> k;

			v.clear();
			for (int i = 0; i < n; ++ i) v.pb(cnt[i]);

			for (int i = 0; i <= x; ++ i) k -= v[i];
			k = max(k, 0LL);
			
			step = sml = 0;
			for (int i = 0; i <= x; ++ i)
				sml += (f[i] - 1) * v[i];
			Solve(x + 1, k);
			
			if (k <= sml) {
				step += k;
				k = 0;
			}
			
			if (k == 0) cout << step << endl;
			else cout << -1 << endl;
		}
	}
}