#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int f(int n, int k) {
  int res = k;
  if (res == 0) return 0;
  for (int i = 0; i < n; i++) {
    int up = 31 - __builtin_clz(res);
    res = res + up + 1;
  }
  return res;
}
bool inter(int l1, int r1, int l2, int r2) { return !((l1 > r2) || (l2 > r1)); }
struct query {
  int type;
  int t, l, r, x;
};
vector<int> ans[7005];
vector<query> qAdd, qAsk;
vector<int> tAdd, tAsk;
void gen() {
  freopen("a.in", "w", stdout);
  cout << 7000 << " " << 7000 << endl;
  ;
  for (int i = 0; i < 3500; i++) cout << "1 2 1 1" << endl;
  for (int j = 0; j < 3500; j++) cout << "2 1 1" << endl;
  exit(0);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    query q;
    scanf("%d", &q.type);
    if (q.type == 1) {
      scanf("%d %d %d %d", &q.t, &q.l, &q.r, &q.x);
      int l, r;
      l = f(n - q.t, q.l - 1) + 1;
      r = f(n - q.t, q.r);
      q.l = l;
      q.r = r;
      qAdd.push_back(q);
      tAdd.push_back(i);
    } else {
      scanf("%d %d", &q.t, &q.l);
      int l, r;
      l = f(n - q.t, q.l - 1) + 1;
      r = f(n - q.t, q.l);
      q.l = l;
      q.r = r;
      qAsk.push_back(q);
      tAsk.push_back(i);
    }
  }
  for (int i = 0; i < qAdd.size(); i++) {
    int l = qAdd[i].l;
    int r = qAdd[i].r;
    int t = qAdd[i].t;
    int x = qAdd[i].x;
    for (int j = 0; j < qAsk.size(); j++) {
      if (tAdd[i] <= tAsk[j] && t >= qAsk[j].t &&
          inter(l, r, qAsk[j].l, qAsk[j].r)) {
        ans[j].push_back(x);
      }
    }
  }
  for (int i = 0; i < qAsk.size(); i++) {
    sort(ans[i].begin(), ans[i].end());
    int len = unique(ans[i].begin(), ans[i].end()) - ans[i].begin();
    printf("%d\n", len);
  }
  return 0;
}
