#include <bits/stdc++.h>
using namespace std;
const int N = 7000 + 10;
int cnt[1000000 + 1];
struct Node {
  int l, r, x;
  Node() {}
  Node(int l, int r, int x) : l(l), r(r), x(x) {}
};
vector<Node> level[N];
int main() {
  int n, m, t, l, r, x, v, op;
  int Tim = 1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d%d", &t, &l, &r, &x);
      level[t].push_back(Node(l, r, x));
    } else {
      scanf("%d%d", &t, &v);
      int L = v, R = v, res = 0;
      Tim++;
      while (t <= n) {
        for (int j = 0; j < level[t].size(); j++) {
          Node &z = level[t][j];
          if (!(z.r < L || z.l > R)) {
            if (cnt[z.x] != Tim) {
              cnt[z.x] = Tim;
              res++;
            }
          }
        }
        if (L != 1) {
          L += log2(L - 1.0) + 1;
        }
        if ((R & -R) == R) {
          if (R != 1) {
            R += log2(R - 1.0) + 2;
          } else {
            R = 2;
          }
        } else
          R += log2(R - 1.0) + 1;
        t++;
      }
      printf("%d\n", res);
    }
  }
  return 0;
}
