#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
int n, m, l[200001], r[200001];
vector<pair<pair<int, int>, int> > vec[7011];
set<int> ans;
int main() {
  int t, cnt = 0, a, b, lev, x;
  for (int i = 1; i < 200001; i++) {
    r[i] = l[i] = i + cnt;
    if (!(i & (i - 1))) {
      cnt++;
      r[i] = i + cnt;
    }
  }
  cin >> n >> m;
  while (m--) {
    cin >> t >> lev >> a;
    if (t == 1) {
      cin >> b >> x;
      vec[lev].push_back(make_pair(make_pair(a, b), x));
    } else {
      ans.clear();
      b = a;
      for (int i = lev; i < n + 1; i++) {
        for (int j = 0; j < vec[i].size(); j++) {
          if (a <= vec[i][j].first.first && b >= vec[i][j].first.first)
            ans.insert(vec[i][j].second);
          else if (a <= vec[i][j].first.second && b >= vec[i][j].first.second)
            ans.insert(vec[i][j].second);
          else if (vec[i][j].first.first <= a && vec[i][j].first.second >= b)
            ans.insert(vec[i][j].second);
        }
        a = l[a], b = r[b];
      }
      cout << ans.size() << endl;
    }
  }
  return 0;
}
