#include <bits/stdc++.h>
using namespace std;
int n, m;
int val[1000010];
struct {
  int pre, l, r, v;
} e[7050];
int level[7050];
int tops;
int ans[7050];
int pos[200050];
int sign;
int p2[25];
int main() {
  p2[2] = 2;
  p2[1] = 1;
  p2[0] = 0;
  for (int i = 3; i < 25; i++) p2[i] = p2[i - 1] * 2;
  for (int i = 0; i < 200000; i++) {
    for (int j = 24; j >= 0; j--)
      if (i >= p2[j]) {
        pos[i] = j;
        break;
      }
  }
  while (scanf("%d %d", &n, &m) != EOF) {
    memset(val, 0, sizeof(val));
    for (int i = 0; i <= n; i++) {
      level[i] = -1;
    }
    int t1, t2, t3, t4, t5;
    tops = 0;
    sign = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d", &t1);
      if (t1 == 1) {
        scanf("%d %d %d %d", &t2, &t3, &t4, &t5);
        e[tops].l = t3, e[tops].r = t4;
        e[tops].v = t5;
        e[tops].pre = level[t2];
        level[t2] = tops++;
      } else {
        sign++;
        scanf("%d %d", &t2, &t3);
        int l = t3, r = t3, ptr;
        for (int j = t2; j <= n; j++) {
          ptr = level[j];
          while (ptr != -1) {
            if (e[ptr].r < l || e[ptr].l > r)
              ptr = e[ptr].pre;
            else {
              if (val[e[ptr].v] != sign) ans[sign]++;
              val[e[ptr].v] = sign;
              ptr = e[ptr].pre;
            }
          }
          l += pos[l - 1];
          r += pos[r];
        }
        printf("%d\n", ans[sign]);
      }
    }
  }
  return 0;
}
