#include <bits/stdc++.h>
using namespace std;
int s[200001], u;
vector<int> query[200001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < 200001; i++) {
    s[i] += s[i - 1];
    if (i & (1 << u)) s[i]++, u++;
  }
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x;
      query[t].push_back(l), query[t].push_back(r), query[t].push_back(x);
    } else {
      int t, v;
      cin >> t >> v;
      int ri = v, le = v;
      set<int> ans;
      while (t <= n) {
        for (int i = 0; i < query[t].size(); i += 3) {
          int left = query[t][i];
          int right = query[t][i + 1];
          int x = query[t][i + 2];
          if (ri >= left && le <= right) ans.insert(x);
        }
        le = le + s[le - 1];
        ri = ri + s[ri];
        t++;
      }
      cout << ans.size() << endl;
    }
  }
  return 0;
}
