#include <bits/stdc++.h>
using namespace std;
int sz[7010], pre[110010];
int ck(int x) {
  int ans = 0;
  while (x) {
    x /= 2;
    ans++;
  }
  return ans;
}
bool use[110010];
int use2[1000010];
int a[1000010];
int t[100010], x[100010], l[100010], r[100010], ope[100010];
int fa[110010][20];
int ck2(int x, int dep) {
  for (int i = 19; i >= 0; i--) {
    if (dep & (1 << i)) x = fa[x][i];
  }
  return x;
}
int main() {
  for (int i = 1; i <= 110000; i *= 2) {
    use[i] = 1;
  }
  int n, m, tot2 = 0;
  scanf("%d%d", &n, &m);
  sz[1] = 1;
  sz[2] = 2;
  pre[1] = 1;
  pre[2] = 1;
  for (int i = 3; i <= n; i++) {
    int ne = ck(sz[i - 1]), tot = sz[i - 1] + 1;
    sz[i] = sz[i - 1] + ne;
    for (int j = sz[i - 2] + 1; j <= sz[i - 1]; j++) {
      if (use[j]) {
        pre[tot] = pre[tot + 1] = j;
        tot += 2;
      } else {
        pre[tot] = j;
        tot++;
      }
    }
    tot2 += sz[i];
  }
  for (int i = 1; i < 110000; i++) {
    fa[i][0] = pre[i];
    for (int j = 1; j < 20; j++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  }
  int Cnt = 0;
  set<int> ss;
  for (int i = 0; i < m; i++) {
    scanf("%d", &ope[i]);
    if (ope[i] == 1) {
      scanf("%d%d%d%d", &t[i], &l[i], &r[i], &x[i]);
    } else {
      ss.clear();
      int tt, xx;
      scanf("%d%d", &tt, &xx);
      for (int j = 0; j < i; j++) {
        if (ope[j] == 2) continue;
        if (t[j] < tt) continue;
        int l1 = ck2(l[j], t[j] - tt);
        int r1 = ck2(r[j], t[j] - tt);
        if (l1 <= xx && r1 >= xx) {
          ss.insert(x[j]);
        }
      }
      printf("%d\n", ss.size());
    }
  }
  return 0;
}
