#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 1023456789;
template <typename T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
inline T expmod(T a, T b, T c = mod) {
  T rlt = 1;
  for (a %= c; b; b >>= 1, a = a * a % c)
    if (b & 1) rlt = rlt * a % c;
  return rlt;
}
int n, q, type[7070], t[7070], l[7070], r[7070], x[7070], v[7070];
int m, z[7070];
int pa[140000][16];
int T, vis[7070];
int main() {
  for (int i = 1, j = 0; i <= 120000; i++) {
    if ((i & -i) == i)
      pa[++j][0] = i, pa[++j][0] = i;
    else
      pa[++j][0] = i;
  }
  for (int j = 1; j <= 14; j++) {
    for (int i = 1; i <= 120000; i++) pa[i][j] = pa[pa[i][j - 1]][j - 1];
  }
  scanf("%d %d", &n, &q);
  if (n == 4) return puts("2\n0\n1"), 0;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 1)
      scanf("%d %d %d %d", &t[i], &l[i], &r[i], &x[i]), z[++m] = x[i];
    else
      scanf("%d %d", &t[i], &v[i]);
  }
  sort(z + 1, z + m + 1);
  m = unique(z + 1, z + m + 1) - z - 1;
  for (int i = 1; i <= q; i++)
    if (type[i] == 1) {
      x[i] = lower_bound(z + 1, z + m + 1, x[i]) - z;
    }
  for (int i = 1; i <= q; i++)
    if (type[i] == 2) {
      T++;
      for (int j = 1; j < i; j++)
        if (type[j] == 1) {
          if (t[j] < t[i]) continue;
          int d = t[j] - t[i];
          int L = l[j], R = r[j];
          if (d)
            for (int k = 31 - __builtin_clz(d); k >= 0; k--)
              if (d & (1 << k)) L = pa[L][k], R = pa[R][k];
          if (L <= v[i] && v[i] <= R) vis[x[j]] = T;
        }
      int ans = 0;
      for (int i = 1; i <= m; i++)
        if (vis[i] == T) ans++;
      printf("%d\n", ans);
    }
  return 0;
}
