#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, x;
  void read() { scanf("%d%d%d", &l, &r, &x); }
};
vector<node> level[7001];
int n, m;
const int maxnum = 1000000;
int many[maxnum];
void init() {
  for (int i = 1; i < maxnum; i++) {
    many[i] = many[i - 1];
    if (i & (i - 1)) continue;
    many[i]++;
  }
  for (int i = 1; i < maxnum; i++) {
    many[i] += i;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  while (m--) {
    int ope;
    scanf("%d", &ope);
    if (ope == 1) {
      int t;
      node tmp;
      scanf("%d", &t);
      tmp.read();
      level[t].push_back(tmp);
    } else {
      int t, v;
      scanf("%d%d", &t, &v);
      set<int> s;
      int L = v, R = v;
      for (int i = t; i <= n; i++) {
        for (int j = 0; j < level[i].size(); j++) {
          node tmp = level[i][j];
          if (tmp.l > R || tmp.r < L) continue;
          s.insert(tmp.x);
        }
        L = many[L - 1] + 1;
        R = many[R];
      }
      printf("%d\n", s.size());
    }
  }
  return 0;
}
