#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 7e3 + 5;
struct node {
  int l, r, v;
};
int n, m, L[maxn], R[maxn];
vector<node> v[maxm];
int calc(int d, int x, int y) {
  set<int> s;
  for (int i = d; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j].l <= y && x <= v[i][j].r) s.insert(v[i][j].v);
    }
    if (L[x] == -1)
      x = R[x];
    else
      x = L[x];
    y = R[y];
  }
  return s.size();
}
int main() {
  int deep = 1, p = 3;
  memset(L, -1, sizeof L);
  memset(R, -1, sizeof R);
  L[1] = 1, R[1] = 2;
  for (int i = 2; i < maxn; i++) {
    if ((1 << deep) == i) {
      deep++;
      L[i] = p++;
    }
    R[i] = p++;
  }
  scanf("%d%d", &n, &m);
  while (m--) {
    int op, d, l, r, x;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d%d", &d, &l, &r, &x);
      v[d].push_back({l, r, x});
    } else {
      scanf("%d%d", &d, &x);
      printf("%d\n", calc(d, x, x));
    }
  }
  return 0;
}
