#include <bits/stdc++.h>
using namespace std;
int MSB1(long long x) {
  int d = 0;
  while ((1LL << d) <= x) d++;
  return d;
}
int main() {
  int n, m;
  cin >> n >> m;
  struct Elm {
    int l, r, x;
  };
  vector<vector<Elm>> vals(n);
  while (m--) {
    int op;
    cin >> op;
    if (op == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x, t--;
      vals[t].emplace_back(Elm{l, r, x});
      continue;
    }
    int t, v;
    cin >> t >> v, t--;
    set<int> se;
    for (int l = v, r = v; t < n; t++, l += MSB1(l - 1), r += MSB1(r)) {
      for (auto &e : vals[t])
        if (e.l <= r && l <= e.r) se.emplace(e.x);
    }
    cout << se.size() << endl;
  }
  return 0;
}
