#include <bits/stdc++.h>
using namespace std;
const int nmax = 7000 + 10;
int n, m;
struct seg {
  int l, r, x;
};
vector<seg> segment[nmax];
inline bool isPow2(int x) { return (x & ~(x - 1)) == x; }
inline int lowPow2(int x) {
  int r = 0;
  while (x) {
    r++;
    x >>= 1;
  }
  return r;
}
void count(int lv, int p, set<int> &result) {
  int begin = p, end = p;
  for (int l = lv; l <= n; l++) {
    for (vector<seg>::iterator it = segment[l].begin(); it != segment[l].end();
         it++) {
      if ((it->l >= begin && it->l <= end) ||
          (it->r >= begin && it->r <= end) ||
          (begin >= it->l && end <= it->r)) {
        result.insert(it->x);
      }
    }
    if (l < n) {
      end = end + lowPow2(end);
      begin = begin + lowPow2(begin) - isPow2(begin);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  set<int> result;
  cin >> m;
  while (m--) {
    int o;
    cin >> o;
    if (o == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x;
      seg s;
      s.l = l;
      s.r = r;
      s.x = x;
      segment[t].push_back(s);
    } else {
      int t, v;
      cin >> t >> v;
      count(t, v, result);
      cout << result.size() << endl;
      result.clear();
    }
  }
  return 0;
}
