#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int nn = 1;
  for (int i = 1; i < n; i++) {
    int c = 0;
    for (int j = 0; (1 << j) <= nn; j++) c++;
    nn += c;
  }
  vector<int> P;
  for (int i = 0; i < nn; i++) {
    bool f = false;
    for (int j = 0; (1 << j) <= i + 1; j++)
      if ((1 << j) == i + 1) f = true;
    for (int j = 0; j < (f ? 2 : 1); j++) P.push_back(i);
  }
  vector<int> type(m), t(m), l(m), r(m), x(m), v(m);
  for (int i = 0; i < m; i++) {
    cin >> type[i];
    if (type[i] == 1) {
      cin >> t[i] >> l[i] >> r[i] >> x[i];
      t[i]--, l[i]--, r[i]--;
    } else {
      cin >> t[i] >> v[i];
      t[i]--, v[i]--;
    }
  }
  vector<set<int>> S(m);
  vector<vector<int>> qn(n);
  for (int i = m - 1; i >= 0; i--) {
    if (type[i] == 1) {
      int tt = t[i];
      int tl = l[i];
      int tr = r[i];
      for (; tt >= 0; tt--) {
        for (int j = 0; j < (int)qn[tt].size(); j++)
          if (tl <= v[qn[tt][j]] && v[qn[tt][j]] <= tr)
            S[qn[tt][j]].insert(x[i]);
        tl = P[tl];
        tr = P[tr];
      }
    } else {
      qn[t[i]].push_back(i);
    }
  }
  for (int i = 0; i < m; i++)
    if (type[i] == 2) cout << S[i].size() << endl;
}
