#include <bits/stdc++.h>
using namespace std;
struct interval {
  int l;
  int r;
  int x;
};
int N, M, L;
vector<interval> v[7010];
unordered_set<int> ret;
int cnt(int x) {
  int count = x;
  while (x) {
    x /= 2;
    ++count;
  }
  return count;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; ++i) {
    int type, t, l, r, x;
    scanf("%d", &type);
    if (type == 1) {
      interval tmp;
      scanf("%d%d%d%d", &t, &l, &r, &x);
      tmp.l = l;
      tmp.r = r;
      tmp.x = x;
      v[t].push_back(tmp);
    } else {
      scanf("%d%d", &t, &x);
      int l, r;
      ret.clear();
      for (l = r = x; t <= N; ++t) {
        for (int j = 0; j < (int)v[t].size(); ++j) {
          if (v[t][j].l <= l && l <= v[t][j].r ||
              v[t][j].l <= r && r <= v[t][j].r ||
              l <= v[t][j].l && v[t][j].l <= r ||
              l <= v[t][j].r && v[t][j].r <= r) {
            ret.insert(v[t][j].x);
          }
        }
        l = cnt(l - 1) + 1;
        r = cnt(r - 1) + 1 + ((r & (r - 1)) == 0);
      }
      printf("%d\n", ret.size());
    }
  }
  return 0;
}
