#include <bits/stdc++.h>
using namespace std;
int n, Q;
struct data {
  int l, r, x;
};
vector<data> vec[7010];
int go(int lev, int now) {
  int i, j, L, R, t;
  set<int> s;
  L = now, R = now;
  for (i = lev; i <= n; i++) {
    for (j = 0; j < vec[i].size(); j++) {
      if ((vec[i][j].l <= L && L <= vec[i][j].r) ||
          (vec[i][j].l <= R && R <= vec[i][j].r))
        s.insert(vec[i][j].x);
      else if ((L <= vec[i][j].l && vec[i][j].l <= R) ||
               (L <= vec[i][j].r && vec[i][j].r <= R))
        s.insert(vec[i][j].x);
    }
    t = L - 1;
    for (j = 0; j <= 30; j++) {
      if (L - 1 >= (1 << j))
        t++;
      else
        break;
    }
    L = t + 1;
    t = R - 1;
    for (j = 0; j <= 30; j++) {
      if (R - 1 >= (1 << j))
        t++;
      else
        break;
    }
    if (R == (1 << j))
      R = t + 2;
    else
      R = t + 1;
  }
  return s.size();
}
int main(void) {
  int op, lev, x;
  data p;
  scanf("%d %d", &n, &Q);
  for (; Q >= 1; Q--) {
    scanf("%d %d", &op, &lev);
    if (op == 1) {
      scanf("%d %d %d", &p.l, &p.r, &p.x);
      vec[lev].push_back(p);
    } else {
      scanf("%d", &x);
      printf("%d\n", go(lev, x));
    }
  }
  return false;
}
