#include <bits/stdc++.h>
using namespace std;
int ad[1100000], L[1100000], R[1100000], r[1100000], l[1100000], h[1100000],
    f[1100000], row[1100000];
int main() {
  int m = 0, cnt = 0, i, j, c, n, runs, x, y;
  scanf("%d %d\n", &n, &runs);
  for (i = 0; i < 21; i++) ad[1 << i] = 1;
  for (i = 1; i < 1100000; i++) ad[i] += ad[i - 1];
  for (i = 0; i < runs; i++) {
    scanf("%d", &c);
    if (c == 1) {
      scanf("%d %d %d %d", row + m, L + m, R + m, h + m);
      m++;
    }
    if (c == 2) {
      cnt = 0;
      scanf("%d %d", &x, &y);
      l[x] = y - 1;
      r[x] = y;
      for (j = x + 1; j <= n; j++) {
        l[j] = l[j - 1] + ad[l[j - 1]];
        r[j] = r[j - 1] + ad[r[j - 1]];
      }
      for (j = 0; j < m; j++) {
        if (row[j] >= x && !(l[row[j]] >= R[j] || r[row[j]] < L[j]) &&
            f[h[j]] != i) {
          f[h[j]] = i;
          cnt++;
        }
      }
      printf("%d\n", cnt);
    }
  }
  return 0;
}
