#include <bits/stdc++.h>
using namespace std;
struct ev {
  int l, r, x;
  ev(int l = 0, int r = 0, int x = -1) : l(l), r(r), x(x) {}
};
const int MAX_N = 7e3 + 10;
vector<ev> Z[MAX_N];
set<int> Set;
int N;
inline int cntdeg2(int a, bool t) {
  int r = 0;
  if (!t)
    if ((a & ~(a - 1)) == a) --r;
  while (a) ++r, a >>= 1;
  return r;
}
inline int inside(int curlev, int curv) {
  Set.clear();
  int L = curv, R = curv;
  for (; curlev <= N; ++curlev) {
    for (__typeof((Z[curlev]).begin()) e = (Z[curlev]).begin();
         e != (Z[curlev]).end(); ++e)
      if ((e->r >= L && e->l <= L) || (e->r >= R && e->l <= R) ||
          (e->r <= R && e->l >= L))
        Set.insert(e->x);
    L += cntdeg2(L, 0);
    R += cntdeg2(R, 1);
  }
  return Set.size();
}
int main() {
  int M;
  cin >> N >> M;
  for (int i = 0; i < int(M); ++i) {
    int type, t, l, r, x;
    cin >> type;
    if (type == 1) {
      cin >> t >> l >> r >> x;
      Z[t].push_back(ev(l, r, x));
    } else {
      cin >> t >> l;
      cout << inside(t, l) << endl;
    }
  }
  return 0;
}
