#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, l, r, n;
  node(int T = 0, int L = 0, int R = 0, int N = 0) {
    t = T;
    l = L;
    r = R;
    n = N;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<node> V;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      b--;
      c--;
      V.push_back(node(a, b, c, d));
    } else {
      int t, v;
      cin >> t >> v;
      v--;
      set<int> S;
      for (int j = 0; j < (int)V.size(); j++) {
        if ((int)S.count(V[j].n)) continue;
        if (V[j].t < t) continue;
        int l = V[j].l;
        int r = V[j].r;
        int ver = V[j].t;
        while (ver != t) {
          int tm1, tm2;
          tm2 = tm1 = 0;
          while (l - tm1 >= (1 << tm1)) tm1++;
          if (tm1) tm1--;
          while (r - tm2 >= (1 << tm2)) tm2++;
          if (tm2) tm2--;
          int tmp = 1;
          if (l == 0 && r == 0) ver = t;
          if (l == 0 && r != 0) {
            tmp = (r - (1 << tm2) + 1) / (tm2 + 1);
            r -= min(ver - t, tmp) * (tm2 + 1);
          }
          if (l != 0 && r == 0) {
            tmp = (l - (1 << tm1) + 1) / (tm1 + 1);
            l -= min(ver - t, tmp) * (tm1 + 1);
          }
          if (l != 0 && r != 0) {
            tmp = min((l - (1 << tm1) + 1) / (tm1 + 1),
                      (r - (1 << tm2) + 1) / (tm2 + 1));
            l -= min(ver - t, tmp) * (tm1 + 1);
            r -= min(ver - t, tmp) * (tm2 + 1);
          }
          if (t > ver - tmp)
            ver = t;
          else
            ver = ver - tmp;
        }
        if (v >= l)
          if (v <= r) S.insert(V[j].n);
      }
      cout << (int)S.size() << endl;
    }
  }
  return 0;
}
