#include <bits/stdc++.h>
using namespace std;
struct interval {
  int l, r;
  int x;
  interval(int x, int l, int r) : x(x), l(l), r(r){};
};
vector<interval> level[700123];
bool intersect(int l1, int r1, int l2, int r2) {
  if (l2 > r1 || l1 > r2) return false;
  return true;
}
int main() {
  int n, q;
  scanf(" %d %d", &n, &q);
  int next[700123];
  next[0] = 0;
  int nxt = 0;
  int pot2 = 1;
  for (int i = 1; i < 700123; i++) {
    if (i >= pot2) {
      nxt += 2;
      next[i] = nxt;
      pot2 *= 2;
    } else {
      nxt++;
      next[i] = nxt;
    }
  }
  while (q--) {
    int h;
    int t, l, r, x;
    scanf(" %d", &t);
    if (t == 1) {
      scanf(" %d %d %d %d", &h, &l, &r, &x);
      level[h].push_back(interval(x, l, r));
    } else {
      scanf(" %d %d", &h, &r);
      l = r - 1;
      set<int> has;
      for (; h <= n; h++) {
        for (int i = 0; i < level[h].size(); i++) {
          if (intersect(l + 1, r, level[h][i].l, level[h][i].r))
            has.insert(level[h][i].x);
        }
        l = next[l];
        r = next[r];
      }
      printf("%d\n", has.size());
    }
  }
  return 0;
}
