#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int T[7777], L[7777], R[7777], X[7777];
int st[7777], ed[7777], vst[1100000], runs;
int calc(int n) {
  if (!n) return 0;
  return n + 32 - (__builtin_clz(n));
}
int main() {
  int n, m, ct = 0;
  cin >> n >> m;
  int tp, t, v;
  for (int i = 0; i < m; i++) {
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d %d %d %d", T + ct, L + ct, R + ct, X + ct);
      ct++;
    } else {
      scanf("%d %d", &t, &v);
      st[t] = ed[t] = v;
      for (int j = t + 1; j <= n; j++) {
        st[j] = calc(st[j - 1] - 1) + 1;
        ed[j] = calc(ed[j - 1]);
      }
      runs++;
      int ans = 0;
      for (int j = 0; j < ct; j++) {
        if (T[j] < t) continue;
        if (max(L[j], st[T[j]]) <= min(R[j], ed[T[j]])) {
          if (vst[X[j]] != runs) ans++;
          vst[X[j]] = runs;
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
