#include <bits/stdc++.h>
using namespace std;
const int N = 7000;
const int MAX = 200000;
const int V = 1000000;
int n, m, fa[MAX + 100], vis[V + 10], lg[MAX + 100];
struct data {
  int l, r, x;
};
vector<data> v[N + 10];
void pre() {
  for (int i = 1; i <= MAX; i++) {
    lg[i] = log2(i);
    if ((1 << lg[i]) == i) {
      fa[i + lg[i]] = i;
      fa[i + lg[i] + 1] = i;
    } else
      fa[i + lg[i] + 1] = i;
  }
}
void Add(int t, int l, int r, int x) {
  data now;
  now.l = l;
  now.r = r;
  now.x = x;
  v[t].push_back(now);
}
int Query(int t, int vx) {
  int nowl = vx, nowr = vx, ans = 0;
  for (int i = t; i <= n; i++) {
    int sz = v[i].size();
    for (int j = 0; j < sz; j++) {
      data k = v[i][j];
      if (k.r < nowl || k.l > nowr) continue;
      if (vis[k.x] == 0) ans++;
      vis[k.x] = 1;
    }
    if (nowl == (1 << lg[nowl]))
      nowl += lg[nowl];
    else
      nowl += lg[nowl] + 1;
    nowr += lg[nowr] + 1;
  }
  for (int i = t; i <= n; i++) {
    int sz = v[i].size();
    for (int j = 0; j < sz; j++) vis[v[i][j].x] = 0;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  pre();
  for (int i = 1; i <= m; i++) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int t, l, r, x;
      scanf("%d%d%d%d", &t, &l, &r, &x);
      Add(t, l, r, x);
    } else {
      int t, vx;
      scanf("%d%d", &t, &vx);
      int ans = Query(t, vx);
      printf("%d\n", ans);
    }
  }
  return 0;
}
