#include <bits/stdc++.h>
using namespace std;
// Prioridade
typedef long long   ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i < (int)(b); i++)
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (((a)/__gcd(a, b)) * b)
#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;
// fim da Prioridade

ll solve(int pos, ll val, vll &v){
	ll small = 0, ans = INFLL, curr = 0; 
	for(int i = 0; i <= pos; i++){
		small = small + v[i] * ((1ll << i) - 1);
		val = val - v[i];
	}
	
	if(val <= 0) return ans = 0;
	
	int id = pos + 1;
	
	while(id < v.size()){
		ll qtd = (1 << (id - pos));
		ll need = min(val / qtd, v[id]);
		val -= need * qtd;
		curr += need * (qtd - 1);
		small += need * qtd * ((1 << pos) - 1);
		if(need == v[id]) id++;
		else 				break;
	}	
	
	if(val <= 0) return ans = curr;
	if(id == v.size()){
		if(val > small) return ans = -1;
		else 			return ans = curr + val;
	}
	while(id > pos){
		if(small >= val){
			ans = min(ans, curr + val);
		}
		curr++;
		id--;
		ll qtd = (1 << (id - pos));
		if(qtd <= val){
			val -= qtd;
			curr += qtd - 1;
			small += qtd * ((1ll << pos) - 1ll);
		}
	}
	
	ans = min(ans, curr);
	return ans;
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	
	vll v(n);
	
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	
	for(int i = 0; i < q; i++){
		int op;
		cin >> op;
		if(op == 1){ // update 
			ll idx, val;
			cin >> idx >> val;
			v[idx] = val;
		}else if(op == 2){ //query
			ll x, k;
			cin >> x >> k;
			cout << solve(x, k, v) << endl;
		}
	}
	
	
	return 0;
}









