#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) (x).begin(),(x).end()
#define pb push_back

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q; cin >> n >> q;
    int cnt[n];
    for(int i = 0; i < n; ++i) {
        cin >> cnt[i];
    }
    while(q--) {
        int tp; cin >> tp;
        if(tp == 1) {
            int p, v; cin >> p >> v;
            cnt[p] = v;
        } else {
            int x, k; cin >> x >> k;
            int orig[n];
            for(int i = 0; i < n; ++i) {
                orig[i] = cnt[i];
            }
            int sm = 0, tot = 0, all = 0, res = 0;
            for(int i = 0; i < n; ++i) {
                if(i <= x) {
                    sm += cnt[i] * (1LL << i);
                    tot += cnt[i];
                }
                all += cnt[i] * (1LL << i);
            }
            if(tot >= k) {
                cout << "0\n";
                continue;
            }
            if(all < k) {
                cout << "-1\n";
                continue;
            }
            int ans = 1e18;
            for(int i = x + 1; i < n; ++i) {
                if(tot == k) break;
                int add = 1LL << i - x; 
                int ops = add - 1;
                if(cnt[i] * add + tot <= k) {
                    tot += cnt[i] * add;
                    sm += cnt[i] * (1LL << i);
                    res += cnt[i] * ops;
                    continue;
                }
                if(tot == k) break;
                int diff = k - tot;
                int cur = i;
                while(tot < k && cur > x) {
                    diff = k - tot;
                    int amt = diff / add;
                    tot += amt * add, res += amt * ops;
                    sm += amt * (1LL << cur);
                    if(k == tot) break;
                    if(sm >= k) {
                        ans = min(ans, res + k - tot);
                    }
                    if(cur != x + 1)++res;
                    --cur;
                    add = 1LL << cur - x; ops = add - 1;
                }
                break;
            }
            if(k > tot) {
                res += k - tot;
                tot = k;
            }
            cout << min(ans, res) << "\n";
        }
    }
}   

//CHECK FOR LONG LONG!!!    
//LONG LONG OVERFLOW??
//TLE: didnt take in all the input?
//bitwise operations come super late
//multiset instead of set?
//crashing: not taking input for n or m?
//switch n and m?