#include <bits/stdc++.h>
using namespace std;
const long double E = 1e-7;
const int MOD = 1e9 + 7;
const long long MAX = 2e5 + 1;
inline bool in(int l, int x, int r) { return (l <= x && x <= r); }
bool check(int l1, int r1, int l2, int r2) {
  return (in(l1, l2, r1) || in(l1, r2, r1) || in(l2, l1, r2) || in(l2, r1, r2));
}
int lg[MAX];
inline int getL(int pos) {
  return (pos + lg[pos] + 1 - (pos & (pos - 1) ? 0 : 1));
}
inline int getR(int pos) { return (pos + lg[pos] + 1); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, int> > vec[n];
  lg[0] = lg[1] = 0;
  for (int i = 2, j = 0, need = 2; i < MAX; i++) {
    if (i == need) {
      j++;
      need <<= 1;
    }
    lg[i] = j;
  }
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x;
      vec[t - 1].push_back(make_pair(make_pair(l, r), x));
    } else {
      int t, l, r;
      cin >> t >> l;
      r = l;
      set<int> s;
      for (int i = t - 1; i < n; i++) {
        for (int j = 0; j < (int)vec[i].size(); j++) {
          if (check(l, r, vec[i][j].first.first, vec[i][j].first.second))
            s.insert(vec[i][j].second);
        }
        l = getL(l);
        r = getR(r);
      }
      cout << s.size() << "\n";
    }
  }
}
