#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 7000;
const int MAX_M = 7000;
const int MAX_C = 1 << 17;
const int BN = 13;
struct Op {
  int t, l, r, x;
  Op() {}
  Op(int _t, int _l, int _r, int _x) : t(_t), l(_l), r(_r), x(_x) {}
};
int ps[MAX_C][BN], xs[MAX_M];
Op ops[MAX_M];
inline bool ise2(int a) {
  while (!(a & 1)) a >>= 1;
  return (a == 1);
}
inline int ancestor(int d, int v) {
  for (int i = 0, bi = 1; i < BN; i++, bi <<= 1)
    if (d & bi) v = ps[v][i];
  return v;
}
int main() {
  for (int i = 1, j = 1; j < MAX_C; i++) {
    if (ise2(i))
      ps[j++][0] = i, ps[j++][0] = i;
    else
      ps[j++][0] = i;
  }
  for (int k = 0; k + 1 < BN; k++)
    for (int j = 1; j < MAX_C; j++)
      ps[j][k + 1] = (ps[j][k] > 0) ? ps[ps[j][k]][k] : 0;
  int n, m;
  scanf("%d%d", &n, &m);
  int on = 0;
  while (m--) {
    int cmd;
    scanf("%d", &cmd);
    if (cmd == 1) {
      int t, l, r, x;
      scanf("%d%d%d%d", &t, &l, &r, &x);
      ops[on++] = Op(t, l, r, x);
    } else {
      int t, v;
      scanf("%d%d", &t, &v);
      int xn = 0;
      for (int i = 0; i < on; i++) {
        Op &opi = ops[i];
        if (opi.t >= t) {
          int l = ancestor(opi.t - t, opi.l);
          int r = ancestor(opi.t - t, opi.r);
          if (l <= v && v <= r) xs[xn++] = opi.x;
        }
      }
      sort(xs, xs + xn);
      xn = unique(xs, xs + xn) - xs;
      printf("%d\n", xn);
    }
  }
  return 0;
}
