#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MAXN = 200005;
const int MAXV = 7002 * 7002;
int pai[MAXN];
int st[20][MAXN];
void build_st(int n) {
  for (int i = 0; i < n; ++i) st[0][i] = pai[i];
  for (int i = 1, j = 2; j < n; j <<= 1, i++) {
    for (int k = 0; k < n; k++) {
      st[i][k] = st[i - 1][st[i - 1][k]];
    }
  }
}
int find(int v, int x) {
  int r = v;
  for (int i = 0, j = 1; j < MAXN; i++, j <<= 1)
    if (x & j) r = st[i][r];
  return r;
}
bool power_of_two(int x) {
  while (!(x & 1)) x >>= 1;
  return (x == 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(pai, -1, sizeof pai);
  long long cnt = 1;
  pai[0] = 0;
  for (int i = 1; i < MAXN; ++i) {
    if (cnt >= MAXN - 5) break;
    if (power_of_two(i)) {
      pai[cnt++] = i;
    }
    pai[cnt++] = i;
  }
  build_st(MAXN - 5);
  long long n, m;
  vector<pair<pair<int, int>, pair<int, int> > > insertions;
  while (cin >> n >> m) {
    for (int i = 0; i < m; ++i) {
      int op;
      cin >> op;
      if (op == 1) {
        int t, l, r, x;
        cin >> t >> l >> r >> x;
        insertions.push_back(pair<pair<int, int>, pair<int, int> >(
            pair<int, int>(t, x), pair<int, int>(l, r)));
      } else {
        int t, v;
        cin >> t >> v;
        set<int> ans;
        for (int j = 0; j < (int)insertions.size(); ++j) {
          int diff = insertions[j].first.first - t;
          if (diff < 0) continue;
          int l = find(insertions[j].second.first, diff),
              r = find(insertions[j].second.second, diff);
          if (l <= v && v <= r) ans.insert(insertions[j].first.second);
        }
        cout << (int)ans.size() << endl;
      }
    }
  }
  return 0;
}
