#include <bits/stdc++.h>
using namespace std;
const int MAXN = 7000 + 10, MAXM = 1000000 + 10, MAXT = 111100, L = 13;
int n, m, fa[MAXT][L], t[MAXN], l[MAXN], r[MAXN], first[MAXN], idx[MAXM];
pair<int, int> Getp(int t, int first, int second) {
  if (t < 0) return make_pair(-1, -1);
  for (int i = L - 1; i >= 0; --i)
    if (t & (1 << i)) first = fa[first][i], second = fa[second][i];
  return make_pair(first, second);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, p = 0; i < MAXT; ++i) {
    fa[++p][0] = i;
    if ((i & -i) == i) fa[++p][0] = i;
    if (p >= MAXT - 10) break;
  }
  for (int i = 1; i < MAXT; ++i)
    for (int j = 1; j < L; ++j)
      if (fa[i][j - 1])
        fa[i][j] = fa[fa[i][j - 1]][j - 1];
      else
        break;
  int tot = 0;
  for (int i = 1; i <= m; ++i) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1)
      ++tot, scanf("%d%d%d%d", &t[tot], &l[tot], &r[tot], &first[tot]);
    else {
      int fl, v, Tohka = 0;
      scanf("%d%d", &fl, &v);
      for (int j = 1; j <= tot; ++j)
        if (idx[first[j]] != i) {
          pair<int, int> w = Getp(t[j] - fl, l[j], r[j]);
          if (w.first <= v && v <= w.second) idx[first[j]] = i, ++Tohka;
        }
      printf("%d\n", Tohka);
    }
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
