#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = ~0ULL >> 1;
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
int Pow(int base, int n, int mo) {
  if (n == 0) return 1;
  if (n == 1) return base % mo;
  int tmp = Pow(base, n >> 1, mo);
  tmp = (long long)tmp * tmp % mo;
  if (n & 1) tmp = (long long)tmp * base % mo;
  return tmp;
}
const int maxn = 8000;
int n, m, cnt, ty[8000], level[maxn], fa[300000], L[maxn], R[maxn], X[maxn],
    Hash[maxn];
int Left[maxn], Right[maxn];
bitset<7500> b[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); ++i) {
    scanf("%d", &ty[i]);
    if (ty[i] == 1) {
      scanf("%d%d%d%d", &level[i], &L[i], &R[i], &X[i]);
      Hash[++cnt] = X[i];
    } else {
      scanf("%d%d", &level[i], &X[i]);
    }
  }
  sort(Hash + 1, Hash + cnt + 1);
  cnt = unique(Hash + 1, Hash + cnt + 1) - Hash - 1;
  int c = 0, cur = 1;
  for (int i = (1); i <= (200000); ++i) {
    if (cur == i) {
      fa[++c] = i;
      fa[++c] = i;
      cur <<= 1;
    } else
      fa[++c] = i;
  }
  for (int i = (1); i <= (m); ++i) {
    if (ty[i] == 1) {
      int cur = L[i];
      for (int j = (level[i]); j >= (1); --j) {
        Left[j] = cur;
        cur = fa[cur];
      }
      cur = R[i];
      for (int j = (level[i]); j >= (1); --j) {
        Right[j] = cur;
        cur = fa[cur];
      }
      int h = lower_bound(Hash + 1, Hash + cnt + 1, X[i]) - Hash;
      for (int j = (i + 1); j <= (m); ++j)
        if (ty[j] == 2 && level[j] <= level[i]) {
          if (X[j] >= Left[level[j]] && X[j] <= Right[level[j]]) b[j][h] = 1;
        }
    } else
      printf("%d\n", b[i].count());
  }
  return 0;
}
