#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > v[6000005];
int arr[6000005];
int main() {
  int n, m, t, l, r, x, pos, type;
  cin >> n >> m;
  set<int> s;
  for (int i = 0; i < 6000005; i++) arr[i] = 0;
  for (int i = 1; i < 6000005; i *= 2) arr[i] = 1;
  for (int i = 1; i < 6000005; i++) arr[i] += arr[i - 1];
  while (m--) {
    cin >> type;
    if (type == 1) {
      cin >> t >> l >> r >> x;
      v[t].push_back(make_pair(make_pair(l, r), x));
    } else {
      cin >> t >> pos;
      l = pos;
      r = pos;
      s.clear();
      for (; t <= n; t++) {
        int si = v[t].size();
        for (int i = 0; i < si; i++) {
          if (v[t][i].first.first <= r && v[t][i].first.second >= l)
            s.insert(v[t][i].second);
        }
        l = l - 1 + arr[l - 1] + 1;
        r = r + arr[r];
      }
      cout << s.size() << endl;
    }
  }
  return 0;
}
