#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
const int MAXM = 7100;
const int MAXB = 20;
int N, M;
int Next[MAXB + 2][MAXN];
int flo[MAXN], fhi[MAXN];
vector<int> l[MAXM], r[MAXM], x[MAXM];
int s[MAXM];
int ns;
int main() {
  Next[0][0] = 0;
  Next[0][1] = 1;
  for (int i = 2; i < MAXN; i++) {
    int l = Next[0][i - 1];
    if ((l & (l - 1)) || (l == Next[0][i - 2]))
      Next[0][i] = l + 1;
    else
      Next[0][i] = l;
  }
  for (int i = 1; i < MAXN; i++) {
    if (Next[0][i] != Next[0][i - 1]) {
      flo[Next[0][i]] = i;
      fhi[Next[0][i - 1]] = i - 1;
    }
  }
  for (int i = 0; i < MAXB; i++)
    for (int j = 1; j < MAXN; j++) Next[i + 1][j] = Next[i][Next[i][j]];
  cin >> N >> M;
  for (int m = 0; m < M; m++) {
    int type;
    cin >> type;
    if (type == 1) {
      int t, lx, rx, xx;
      cin >> t >> lx >> rx >> xx;
      l[t].push_back(lx);
      r[t].push_back(rx);
      x[t].push_back(xx);
    } else {
      int t, vlo, vhi;
      cin >> t >> vlo;
      vhi = vlo;
      ns = 0;
      for (int i = t; i <= N; i++) {
        for (int j = 0; j < l[i].size(); j++) {
          if (l[i][j] <= vhi && vlo <= r[i][j]) {
            s[ns] = x[i][j];
            ns++;
          }
        }
        vlo = flo[vlo];
        vhi = fhi[vhi];
      }
      if (ns == 0) {
        cout << "0\n";
        continue;
      }
      sort(s, s + ns);
      int ans = 1;
      for (int i = 1; i < ns; i++)
        if (s[i] != s[i - 1]) ans++;
      cout << ans << "\n";
    }
  }
  return 0;
}
