#include <bits/stdc++.h>
using namespace std;
typedef struct tri {
  uint32_t x;
  uint64_t l, r;
} tri;
struct tri_compare {
  bool operator()(const tri& lhs, const tri& rhs) const {
    if (lhs.x == rhs.x) return lhs.l < rhs.l;
    return lhs.x < rhs.x;
  }
};
inline uint32_t log(uint64_t v) {
  const uint64_t b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000, 0xFFFFFFFF00000000};
  const uint32_t S[] = {1, 2, 4, 8, 16, 32};
  int i;
  register uint32_t r = 0;
  for (i = 5; i >= 0; i--) {
    if (v & b[i]) {
      v >>= S[i];
      r |= S[i];
    }
  }
  return r;
}
inline uint64_t left_child(uint32_t x) {
  if (x == 1) return 1;
  return x + log(x - 1) + 1;
}
inline uint64_t right_child(uint32_t x) {
  if (x == 1) return 2;
  if ((x - 1) & x) return x + log(x - 1) + 1;
  return x + log(x - 1) + 2;
}
bool overlap(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
  uint64_t l = max(a, c);
  uint64_t r = min(b, d);
  return r >= l;
}
set<tri, tri_compare> A[7000 + 50];
set<uint32_t> B[7000 + 50];
int main() {
  int i, j, type;
  uint32_t n, m, t, x;
  uint64_t l, r, v, lvl, left, right;
  set<tri>::iterator it;
  set<uint32_t> ans;
  cin >> n >> m;
  while (m-- > 0) {
    cin >> type;
    if (type == 1) {
      cin >> t >> l >> r >> x;
      if (B[t].find(x) != B[t].end()) {
        for (it = A[t].begin(); it != A[t].end();) {
          if ((*it).x == x && overlap((*it).l, (*it).r, l, r)) {
            l = min((*it).l, l);
            r = max((*it).r, r);
            A[t].erase(it++);
          } else
            ++it;
        }
      }
      B[t].insert(x);
      A[t].insert((tri){x, l, r});
    }
    if (type == 2) {
      ans.clear();
      cin >> t >> v;
      left = v;
      right = v;
      for (i = t; i <= n; i++) {
        for (it = A[i].begin(); it != A[i].end(); it++) {
          lvl = i - t;
          if (overlap(left, right, (*it).l, (*it).r)) {
            ans.insert((*it).x);
          }
        }
        left = left_child(left);
        right = right_child(right);
      }
      cout << ans.size() << "\n";
    }
  }
}
