#include <bits/stdc++.h>
using namespace std;
const int MAXN = 7010;
const int MAXNODE = MAXN * 30;
int l[MAXNODE], r[MAXNODE];
int vis[1000010];
struct seg {
  int color, l, r;
  seg() {}
  seg(int color_, int l_, int r_) {
    color = color_;
    l = l_;
    r = r_;
  }
};
vector<seg> levels[MAXN];
int n, m;
void prework() {
  int cnt = 0, next = 1;
  for (int i = 1; i <= MAXNODE && cnt < MAXNODE; i++) {
    if (i == next) {
      next = next << 1;
      l[i] = ++cnt;
      r[i] = ++cnt;
    } else
      l[i] = r[i] = ++cnt;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int cas = 0;
  prework();
  while (m--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int t, L, R, x;
      scanf("%d%d%d%d", &t, &L, &R, &x);
      levels[t].push_back(seg(x, L, R));
    } else {
      int t, v;
      scanf("%d%d", &t, &v);
      int L, R, ans = 0;
      L = R = v;
      cas++;
      while (t <= n) {
        for (int i = 0; i < levels[t].size(); i++) {
          if (levels[t][i].r < L || levels[t][i].l > R)
            continue;
          else {
            if (vis[levels[t][i].color] == cas)
              continue;
            else {
              ans++;
              vis[levels[t][i].color] = cas;
            }
          }
        }
        L = l[L];
        R = r[R];
        t++;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
