#include <bits/stdc++.h>
using namespace std;
const int M = 1000005;
int lc[M], rc[M], vis[M], arr[M];
vector<array<int, 3> > uwu[M];
void init() {
  int cnt = 0;
  for (int pos = 1; pos < M; pos++) {
    if ((pos & (pos - 1)) == 0) {
      lc[pos] = cnt + 1;
      rc[pos] = cnt + 2;
      cnt += 2;
    } else {
      lc[pos] = cnt + 1;
      rc[pos] = cnt + 1;
      cnt += 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int n, m;
  cin >> n >> m;
  memset(vis, 0, sizeof(vis));
  while (m--) {
    int type;
    cin >> type;
    if (type == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x;
      uwu[t].push_back({x, l, r});
    } else {
      int t, v;
      cin >> t >> v;
      int ans = 0, l = v, r = v, iter = 0;
      for (; t <= n; t++) {
        for (auto pp : uwu[t]) {
          if (vis[pp[0]]) continue;
          if (l <= pp[2] && pp[1] <= r) {
            arr[iter] = pp[0];
            vis[pp[0]] = 1;
            ans++;
            iter++;
          }
        }
        l = lc[l];
        r = rc[r];
      }
      cout << ans << '\n';
      for (int i = 0; i < iter; i++) {
        vis[arr[i]] = 0;
      }
    }
  }
  return 0;
}
