#include <bits/stdc++.h>
using namespace std;
clock_t st, ed;
std::mt19937 rnd(time(0));
template <typename T>
void debug(T begin, T ed) {
  for (T i = begin; i != ed; i++) cout << *i << '\t';
  cout << '\n';
}
const int N = 7e3 + 10;
struct seg {
  int l, r, col;
};
vector<seg> L[N];
int n, m;
set<int> s;
int cal(int x) {
  int b = 1, c = 0;
  while (b <= x) b <<= 1, c++;
  return x + c;
}
void dfs(int dep, int l, int r) {
  if (dep > n) return;
  for (seg& sg : L[dep]) {
    if (sg.l > r or sg.r < l) continue;
    s.insert(sg.col);
  }
  dfs(dep + 1, cal(l - 1) + 1, cal(r));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int dep, l, r, x;
      cin >> dep >> l >> r >> x;
      L[dep].push_back({l, r, x});
    } else {
      int dep, idx;
      cin >> dep >> idx;
      s.clear();
      dfs(dep, idx, idx);
      cout << s.size() << '\n';
    }
  }
}
