#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:600000000")
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)4e18;
const string name = "b";
const int NMAX = 7010;
int n, q, cnt[NMAX];
int a[NMAX], b[NMAX], c[NMAX], d[NMAX], tp[NMAX], l[NMAX], r[NMAX];
vector<int> ans;
int used[1010100], L[100 * NMAX], R[100 * NMAX];
int main() {
  cin >> n >> q;
  cnt[1] = 1;
  memset(L, 255, sizeof(L));
  memset(R, 255, sizeof(R));
  for (int level = 1; level < n; level = level + 1) {
    cnt[level + 1] = 0;
    for (int position = 1; position <= cnt[level]; position = position + 1) {
      if (!(position & (position - 1))) {
        L[position] = cnt[level + 1] + 1;
        R[position] = cnt[level + 1] + 2;
        cnt[level + 1] = cnt[level + 1] + 2;
      } else {
        R[position] = cnt[level + 1] + 1;
        L[position] = R[position];
        cnt[level + 1] = cnt[level + 1] + 1;
      }
    }
  }
  memset(used, 0, sizeof(used));
  for (int i = 0; i < (int)q; i++) {
    scanf("%d", &tp[i]);
    if (tp[i] == 1) {
      scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
    } else {
      int x, y;
      scanf("%d%d", &x, &y);
      for (int j = 0; j < (int)ans.size(); j++) used[ans[j]] = 0;
      ans.clear();
      l[0] = y, r[0] = y;
      for (int j = 0; j < (int)n - x + 1; j++)
        if (j) {
          l[j] = L[l[j - 1]], r[j] = R[r[j - 1]];
        }
      for (int j = 0; j < (int)i; j++)
        if (tp[j] == 1 && a[j] >= x) {
          if (!(b[j] > r[a[j] - x] || c[j] < l[a[j] - x]))
            if (!used[d[j]]) {
              used[d[j]] = 1;
              ans.push_back(d[j]);
            }
        }
      printf("%d\n", ans.size());
    }
  }
  return 0;
}
