#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define PLL pair<ll,ll>
#define _ <<' '<<
#define pw(x) (1ll<<(x))
#define all(x) (x).begin(),(x).end()
#define header ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nd cout<<endl;
#define sz(x) (ll)((x.size()))
#define sqr(x) (x)*(x)
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
const long long inf = 4e18;
const int infi = 2e9;
ll i, j, n, m, k, qq = 1, fr, to, w, x, y, mod = 998244353;
char ch;

void solve(){
    cin >> n >> w;
    vector<ll> cnt(n);
    for(auto &x : cnt) cin >> x;

    while(w--){
        cin >> ch;
        if(ch == '1'){
            ll pos, val; cin >> pos >> val;
            cnt[pos] = val;
            continue;
        }

        cin >> x >> k;
        for(ll i = 0; i <= x; i++){
            k -= cnt[i];
        }
        if(k <= 0){
            cout << "0\n";
            continue;
        }
        ll ans = 0, last_it = -1;
        vector<ll> ncnt = cnt;

        for(ll i = x + 1; i < n && k > 0; i++){
            if(ncnt[i] == 0) continue;
            if(k >= ncnt[i] * pw(i - x)){
                k -= ncnt[i] * pw(i - x);
                ans += ncnt[i] * (pw(i - x) - 1);
                ncnt[x] += ncnt[i] * pw(i - x);
                ncnt[i] = 0;
            }
            else if(k >= pw(i - x)){
                ll col = k / pw(i - x);
                k -= col * pw(i - x);
                ans += col * (pw(i - x) - 1);
                ncnt[x] += col * pw(i - x);
                ncnt[i] -= col;
                last_it = i;
                break;
            }
            else{
                last_it = i;
                break;
            }
        }

        ll low_cnt = 0;
        for(ll i = 1; i <= x; i++) low_cnt += (pw(i) - 1) * ncnt[i];

        if(low_cnt >= k){
            ans += k;
            cout << ans << '\n';
            continue;
        }
        else if(last_it == -1){
            cout << "-1\n";
            continue;
        }

        if(x == 0){
            for(ll i = last_it; i > x && k > 0; i--){
                if(k >= pw(i - x - 1)){
                    ans += pw(i - x - 1);
                    k -= pw(i - x - 1);
                }
                else ans++;
            }
        }
        else{
            for(ll i = last_it; i > x; i--){
                if(pw(i - x + 1) >= k && pw(i - x) <= k){
                    ans += k - 1;
                    break;
                }
                else ans++;
            }
        }
/*
        //ll kk = k, cur_col = 0;
        for(ll i = last_it; i > x; i--){
            if(k >= pw(i - x - 1)){
                //cur_col += pw(i - x - 1);
                ans += pw(i - x - 1);
                k -= pw(i - x - 1);
            }
            else ans++;
        }

        ans += k;
*/
        cout << ans << '\n';

    }
}

int32_t main()
{
    header
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    if(qq == 0) cin >> qq;
    while(qq--){
        solve();
    }
}
//by rumazius
