#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Seg {
  int l, r, w;
  Seg() {}
  Seg(int l, int r, int w) : l(l), r(r), w(w) {}
};
vector<Seg> op[7010];
int bit[25], f[200000];
void check(int l, int r, const vector<Seg> &vec, set<int> &s) {
  for (int i = 0; i < vec.size(); ++i) {
    if (!(r < vec[i].l or l > vec[i].r)) s.insert(vec[i].w);
  }
}
int main() {
  for (int i = 0; i < 25; ++i) bit[i] = 1 << i;
  for (int i = 0; i < 200000; ++i) f[i] = upper_bound(bit, bit + 25, i) - bit;
  scanf("%d %d", &n, &m);
  for (int i = 0, cmd, t, l, r, w; i < m; ++i) {
    scanf("%d", &cmd);
    if (cmd == 1) {
      scanf("%d %d %d %d", &t, &l, &r, &w);
      op[t].push_back(Seg(l, r, w));
    } else {
      scanf("%d %d", &t, &l);
      r = l;
      set<int> s;
      for (int j = t; j <= n; ++j) {
        check(l, r, op[j], s);
        l += f[l - 1];
        r += f[r];
      }
      printf("%d\n", s.size());
    }
  }
  return 0;
}
