#include <bits/stdc++.h>
using namespace std;
struct state {
  int l, r, val;
  state(int l, int r, int val) : l(l), r(r), val(val) {}
};
int n, m, dl[200011], dr[200011];
vector<state> v[200011];
int powmod(int a, int b) {
  int tmp = 1;
  a %= 1000000009;
  for (; b; b >>= 1) {
    if (b & 1) tmp = (long long)tmp * a % 1000000009;
    a = (long long)a * a % 1000000009;
  }
  return tmp;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void R(int &xx) {
  xx = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
}
inline void R(long long &xx) {
  xx = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
}
int solve(int d, int x, int y) {
  set<int> ans;
  for (int i = d; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++)
      if (v[i][j].l <= y && v[i][j].r >= x) ans.insert(v[i][j].val);
    x = dl[x] == -1 ? dr[x] : dl[x];
    y = dr[y];
  }
  return ans.size();
}
int main() {
  int cnt = 1, p = 3;
  memset(dl, -1, sizeof(dl));
  memset(dr, -1, sizeof(dr));
  dl[1] = 1;
  dr[1] = 2;
  for (int i = 2; i <= 200011 - 1; i++) {
    if ((1 << cnt) == i) cnt++, dl[i] = p++;
    dr[i] = p++;
  }
  int order, d, x, y, val;
  R(n);
  R(m);
  while (m--) {
    R(order);
    if (order == 1) {
      R(d);
      R(x);
      R(y);
      R(val);
      v[d].push_back(state(x, y, val));
    } else {
      R(d);
      R(x);
      printf("%d\n", solve(d, x, x));
    }
  }
  return 0;
}
