#include <bits/stdc++.h>
using namespace std;
int L[7006], R[7006], vis[1000006];
struct qq {
  int l, x, y, v;
  qq() {}
  qq(int _l, int _x, int _y, int _v) { l = _l, x = _x, y = _y, v = _v; }
};
vector<qq> V;
double lg2 = log10(2.0), eps = 1e-10;
double lg[7006];
int cnt(int n) {
  int i;
  for (i = 0; (1 << i) <= n; ++i)
    ;
  return n + i;
}
void pre(int N) {
  int i;
  int n = 1;
  for (i = 2; i <= N; ++i) n += n + cnt(n);
  printf("%d\n", n);
}
void prep(int N, int cur, int node) {
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  L[cur] = R[cur] = node;
  for (++cur; cur <= N; ++cur) {
    if (L[cur - 1] == 1)
      L[cur] = 1;
    else
      L[cur] = cnt(L[cur - 1] - 1) + 1;
    R[cur] = cnt(R[cur - 1]);
  }
}
bool overlap(int x1, int y1, int x2, int y2) {
  if (x2 < x1) {
    swap(x1, x2);
    swap(y1, y2);
  }
  return x2 <= y1;
}
int main() {
  int N, Q;
  int op, l;
  int x, y, v, i, ans;
  while (scanf("%d %d", &N, &Q) != EOF) {
    V.clear();
    memset(vis, -1, sizeof(vis));
    while (Q--) {
      scanf("%d %d", &op, &l);
      if (op == 1) {
        scanf("%d %d %d", &x, &y, &v);
        V.push_back(qq(l, x, y, v));
        continue;
      }
      scanf("%d", &x);
      prep(N, l, x);
      ans = 0;
      for (i = 0; i < V.size(); ++i) {
        l = V[i].l, x = V[i].x, y = V[i].y, v = V[i].v;
        if (L[l] == -1) continue;
        if (overlap(x, y, L[l], R[l])) {
          if (vis[v] != Q) {
            vis[v] = Q;
            ++ans;
          }
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
