#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int NMAX = 35;

int cnt[NMAX];

LL solve(int x, LL k, int n)
{
    LL inPlus = 0, nrOp = 0;

    for(int i = 0; i <= x; i++)
    {
        k -= 1LL * cnt[i];
        inPlus += 1LL * cnt[i] * ((1 << i) - 1);
    }

    if(k <= 0)
        return 0;
    else
    {
        int pos = x + 1;

        while(pos < n)
        {
            LL big = 1 << (pos - x);
            LL minCoef = min(k / big, 1LL * cnt[pos]);
            k -= 1LL * minCoef * big;
            inPlus += 1LL * minCoef * big * ((1 << x) - 1);
            nrOp += 1LL * minCoef * (big - 1);

            if(minCoef == 1LL * cnt[pos])
                pos++;
            else
                break;
        }

        if(pos == n)
        {
            if(k > inPlus)
                return -1;
            else
                return nrOp + k;
        }
        else
        {
            if(k == 0)
                return nrOp;
            else
            {
                LL ans = LLONG_MAX;

                while(pos > x)
                {
                    if(k <= inPlus)
                        ans = min(ans, nrOp + k);

                    nrOp++;
                    pos--;
                    LL big = 1 << (pos - x);

                    if(k >= big)
                    {
                        nrOp += big - 1;
                        k -= big;
                        inPlus += big * ((1 << x) - 1);
                    }
                }

                ans = min(ans, nrOp);

                return ans;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q;

    cin >> n >> q;

    for(int i = 0; i < n; i++)
        cin >> cnt[i];

    for(int i = 0; i < q; i++)
    {
        int c;

        cin >> c;

        if(c == 1)
        {
            int pos, val;

            cin >> pos >> val;
            cnt[pos] = val;
        }
        else
        {
            int x;
            LL k;

            cin >> x >> k;
            cout << solve(x, k, n) << '\n';
        }
    }

    return 0;
}
