#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,q;
int a[35],b[35];
int main(){
    //freopen("input.txt","r",stdin);
    cin>>n>>q;
    for(int i = 0; i < n; ++i)cin>>a[i];
    while(q--){
        ll p,x,k;
        cin>>p>>x>>k;
        if(p == 1){
            a[x] = k;
        }else{
            ll le = 0, ans = 1e18,cur = 0,va = k;
            for(int i = 0; i <= x; ++i){
                le += 1ll * a[i] * ((1ll << i) - 1);
                va -= a[i];
            }
            if(va <= 0){
                 cout<< 0 <<endl;
                 continue;
            }
            int id = x + 1;
            while(id < n){
                ll ad = 1ll << (id - x);
                ll nee = min(1ll * a[id],va / ad);
                //cout<< ad << " " << nee << " " << a[id] << " " << va << endl;
                cur += nee * (ad - 1);
                le += nee * ad * ((1ll << x) - 1);
                va -= nee * ad;
                if(nee == a[id])id++;
                else break;
            }
            if(va <= 0){
                 cout<< cur << "\n";
                 continue;
            }
            if(id >= n){
                 cout<< (va > le ? -1 : cur + va) << "\n";
                 continue;
            }
            while(id > x){
                if(le >= va ) ans = min(ans,cur + va);
                cur++;
                id--;
                ll ad = 1ll << (id - x);
                if(va >= ad){
                    cur += ad - 1;
                    le += ad * ((1ll << x) - 1);
                    va -= ad;
                }
            }
            //cout<< ans << " " << cur << endl ;
            if(va > 0) cout<< -1 << endl;
            else cout<< min(ans,cur) <<endl;
        }
    }
    return 0;
}
