#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
using TPL = pair<PII, PII>;
const int SIZE = 110000, BIT = 13;
TPL a[7005];
int g[1000005], src[BIT][SIZE + 50];
void init() {
  int cnt = 0;
  for (int x = 1; x < SIZE; x++) {
    if ((x - 1) & x) {
      src[0][++cnt] = x;
    } else {
      src[0][++cnt] = x;
      src[0][++cnt] = x;
    }
  }
  for (int o = 1; o < BIT; o++)
    for (int x = 1; x < SIZE; x++) src[o][x] = src[o - 1][src[o - 1][x]];
}
bool gao(int l, int x, int y, int p) {
  if (l < 0) return false;
  while (l) {
    int o = __builtin_ctz(l);
    x = src[o][x];
    y = src[o][y];
    l ^= 1 << o;
  }
  return x <= p && p <= y;
}
int main() {
  init();
  memset(g, 63, sizeof(g));
  int n, m, cnt = 0;
  scanf("%d%d", &n, &m);
  while (m--) {
    int o, l, x, y, v;
    scanf("%d", &o);
    if (o == 1) {
      scanf("%d%d%d%d", &l, &x, &y, &v);
      a[cnt++] = {{l, v}, {x, y}};
    } else {
      int ans = 0;
      scanf("%d%d", &l, &x);
      for (int i = 0; i < cnt; i++) {
        if (g[v = a[i].first.second] == m) continue;
        if (gao(a[i].first.first - l, a[i].second.first, a[i].second.second,
                x)) {
          g[v] = m;
          ans++;
        }
      }
      printf("%d\n", ans);
    }
  }
}
