#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
  ios::sync_with_stdio(0);
  run();
}
int has[7001];
vector<tuple<int, int, int>> consider[7001];
void run() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> renum;
  int ids = 0;
  for (int q = 1; q <= m; q++) {
    int type;
    cin >> type;
    if (type == 1) {
      int lev, l, r, x;
      cin >> lev >> l >> r >> x;
      if (not renum.count(x)) renum[x] = ids++;
      consider[lev].emplace_back(l, r, renum[x]);
    } else {
      int lev, l, r;
      cin >> lev >> l;
      for (r = l; lev <= n; lev++) {
        for (auto j : consider[lev]) {
          if (max(get<0>(j), l) <= min(get<1>(j), r)) has[get<2>(j)] = q;
        }
        if (l > 1) l += (32 - __builtin_clz(l - 1));
        r += (32 - __builtin_clz(r));
      }
      int res = 0;
      for (int j = ids; j--;) res += (has[j] == q);
      cout << res << endl;
    }
  }
}
