// Problem: CF1452F Divide Powers
// Contest: Luogu
// Written by RavenclawOIer on 2020-11-24 20:15:36


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long LL;
int n, q;
const int N = 32;
int a[N];
signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  while (q--) {
    int tp, x, y;
    cin >> tp >> x >> y;
    if (tp == 1) a[x] = y;
    else {
      int leq = 0, cur = 0;
      for (int i = 0; i < x + 1; i++) {
        leq += a[i] * ((1LL << i) - 1);
        y -= a[i];
      }
      if (y <= 0) {
        cout << 0 << endl;
        continue;
      }
      int i = x + 1;
      while (i < n) {
        int add = 1LL << (i - x);
        int req = min(a[i], y / add);
        cur += req * (add - 1);
        y -= add * req;
        leq += req * add * ((1LL << x) - 1);
        if (req == a[i]) i++;
        else break;
      }
      if (y <= 0) {
        cout << cur << endl;
        continue;
      }
      if (i >= n) {
        cout << (y > leq ? -1 : cur + y) << endl;
        continue;
      }
      int ans = 1e18;
      while (i > x) {
        if (leq >= y) {
          ans = min(ans, y + cur);
        }
        cur++;
        i--;
        int add = 1LL << (i - x);
        if (y >= add) {
          cur += add - 1;
          y -= add;
          leq += add * ((1LL << x) - 1);
        }
      }
      cout << min(ans, cur) << endl;
    }
  }
  return 0;
}
