#include <bits/stdc++.h>
using namespace std;
void read() {
  static int sum[150000], cnt[1000010];
  static int L[7010], R[7010], v[7010], dep[7010];
  static int l[7010], r[7010];
  int N = 150000, n, m, id = 0;
  for (int i = 1; i < N; ++i) sum[i] = sum[i - 1] + (i == (i & -i));
  scanf("%d %d", &n, &m);
  for (int i = 1, tot = 0, t; i <= m; ++i) {
    scanf("%d", &t);
    if (t == 1) {
      ++tot;
      scanf("%d %d %d %d", dep + tot, L + tot, R + tot, v + tot);
    } else {
      int x, y, ans = 0;
      scanf("%d %d", &x, &y);
      l[x] = r[x] = y, ++id;
      for (int j = x + 1; j <= n; ++j) {
        l[j] = l[j - 1] + sum[l[j - 1] - 1];
        r[j] = r[j - 1] + sum[r[j - 1] - 1];
        if (r[j - 1] == (r[j - 1] & -r[j - 1])) ++r[j];
      }
      for (int j = 1; j <= tot; ++j)
        if (dep[j] >= x) {
          int d = dep[j];
          if (R[j] >= l[d] && L[j] <= r[d]) {
            if (cnt[v[j]] != id) ++ans;
            cnt[v[j]] = id;
          }
        }
      printf("%d\n", ans);
    }
  }
}
int main() {
  read();
  return 0;
}
