#include <bits/stdc++.h>
using namespace std;
int n, m, cnt[7010], tot, t, x, Cnt, c[7010], l, fa[200010];
struct seg {
  int l, r, t, x;
} p[7010];
struct node {
  int x, dfn, id;
};
vector<node> V[7010];
struct Bit {
  int cnt;
  bool is[7010];
  void Add(int x) {
    if (!is[x]) is[x] = 1, cnt++;
  }
} Ans[7010];
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
inline node make(int x, int dfn, int id) {
  node ans;
  ans.x = x;
  ans.dfn = dfn;
  ans.id = id;
  return ans;
}
int main() {
  read(n);
  read(m);
  cnt[1] = 1;
  for (int i = 1; i < 7000; i++) {
    for (int j = 1; j <= cnt[i]; j++)
      if ((j & (-j)) == j)
        cnt[i + 1] += 2;
      else
        cnt[i + 1]++;
  }
  int cc = 0;
  for (int i = 1; i <= cnt[7000 - 1]; i++)
    if ((i & (-i)) == i)
      fa[++cc] = i, fa[++cc] = i;
    else
      fa[++cc] = i;
  for (int i = 1; i <= m; i++) {
    read(x);
    if (x == 1) {
      read(p[++tot].t);
      read(p[tot].l);
      read(p[tot].r);
      read(p[tot].x);
      c[tot] = p[tot].x;
    } else {
      read(t);
      read(x);
      V[t].push_back(make(x, tot, ++Cnt));
    }
  }
  sort(c + 1, c + tot + 1);
  l = unique(c + 1, c + tot + 1) - (c + 1);
  for (int i = 1; i <= tot; i++) {
    p[i].x = lower_bound(c + 1, c + l + 1, p[i].x) - c;
    int L = p[i].l, R = p[i].r;
    for (int j = p[i].t; j; j--) {
      for (int k = 0; k < V[j].size(); k++)
        if (V[j][k].x >= L && V[j][k].x <= R && V[j][k].dfn >= i)
          Ans[V[j][k].id].Add(p[i].x);
      L = fa[L], R = fa[R];
    }
  }
  for (int i = 1; i <= Cnt; i++) printf("%d\n", Ans[i].cnt);
  return 0;
}
