#include <bits/stdc++.h>
using namespace std;
int n, m;
int bitcount(int x) { return x == 0 ? 0 : bitcount(x / 2) + (x & 1); }
int right(int x) {
  int log;
  for (log = 1; (1 << log) <= x; log++)
    ;
  return log + x;
}
int left(int x) { return bitcount(x) == 1 ? right(x) - 1 : right(x); }
int d1[110000][14], d2[110000][14];
void init(int MAX) {
  memset(d1, -1, sizeof(d1));
  memset(d2, -1, sizeof(d2));
  for (int i = 1; i <= MAX; ++i) {
    d1[i][0] = left(i);
    d2[i][0] = right(i);
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= MAX; i++) {
      int a = d1[i][j - 1];
      if (a != -1 && a <= MAX) d1[i][j] = d1[a][j - 1];
      a = d2[i][j - 1];
      if (a != -1 && a <= MAX) d2[i][j] = d2[a][j - 1];
    }
}
pair<int, int> query(int x, int l) {
  int log;
  for (log = 1; (1 << log) <= l; log++)
    ;
  log--;
  int p1, p2;
  p1 = p2 = x;
  for (int i = log; i >= 0; i--)
    if ((1 << i) & l) {
      p1 = d1[p1][i];
      p2 = d2[p2][i];
    }
  return make_pair(p1, p2);
}
struct Node {
  int op;
  int t, l, r, x, v;
  set<int> s;
} a[7005];
int v[7005];
int main(int argc, char *argv[]) {
  cin >> n >> m;
  int bg = 0, ed = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i].op;
    if (a[i].op == 1) {
      cin >> a[i].t >> a[i].l >> a[i].r >> a[i].x;
    } else {
      cin >> a[i].t >> a[i].v;
      v[ed++] = i;
    }
  }
  init(109332);
  for (int i = 0; i < m; i++) {
    if (a[i].op == 1) {
      for (int k = bg; k < ed; k++) {
        int j = v[k];
        if (a[i].t >= a[j].t) {
          pair<int, int> p = query(a[j].v, a[i].t - a[j].t);
          if (p.second < a[i].l || p.first > a[i].r) continue;
          a[j].s.insert(a[i].x);
        }
      }
    } else {
      bg++;
      cout << a[i].s.size() << endl;
    }
  }
  return 0;
}
