#include <bits/stdc++.h>
using namespace std;
int w_time, n, m, cnt[200000], v[2000000];
int pre[200000][16];
struct sta {
  int L, l, r, x;
} st[200000];
void up(int &l, int &r, int e) {
  for (int k = 0; e; k++, e >>= 1)
    if (e & 1) l = pre[l][k], r = pre[r][k];
}
int main() {
  scanf("%d%d", &n, &m);
  cnt[1] = 1;
  for (int i = 1; i < n; i++) {
    cnt[i + 1] = cnt[i];
    for (int k = cnt[i], j = 1; j <= k; j <<= 1) cnt[i + 1]++;
  }
  for (int i = 1, j = 1, k = 2, p = 2; i <= cnt[n]; i++) {
    pre[i][0] = j;
    k--;
    if (!k) {
      j++;
      if (j == p)
        k = 2, p <<= 1;
      else
        k = 1;
    }
  }
  for (int k = 1; k <= 15; k++)
    for (int i = 1; i <= cnt[n]; i++) pre[i][k] = pre[pre[i][k - 1]][k - 1];
  int r = 0, ans, ch, L, p;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &ch);
    if (1 == ch) {
      ++r;
      scanf("%d%d%d%d", &st[r].L, &st[r].l, &st[r].r, &st[r].x);
    } else {
      scanf("%d%d", &L, &p);
      ++w_time, ans = 0;
      for (int j = 1; j <= r; j++) {
        sta u = st[j];
        if (u.L < L) continue;
        int ll = u.l, rr = u.r;
        up(ll, rr, u.L - L);
        if (p < ll || rr < p) continue;
        if (v[u.x] != w_time) {
          v[u.x] = w_time;
          ans++;
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
