#include <bits/stdc++.h>
using namespace std;
long long P[30];
map<long long, bool> C;
long long Left(long long n) {
  long long ind = 0, i;
  for (i = 0; i < 30; i++) {
    if (P[i] > n - 1) {
      ind = i;
      break;
    }
  }
  return (n - 1) + ind + 1;
}
int main() {
  ios::sync_with_stdio(false);
  long long i, type, t, l, r, x, lev, Lef, Rit, v, j, n, m;
  vector<vector<vector<long long> > > Level(200000);
  vector<long long> T(4);
  set<long long> Ans;
  P[0] = 1;
  C[1] = true;
  for (i = 1; i < 30; i++) {
    P[i] = P[i - 1] * 2;
    C[P[i]] = true;
  }
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> type;
    if (type == 1) {
      cin >> t >> l >> r >> x;
      T[0] = l;
      T[1] = r;
      T[2] = x;
      Level[t - 1].push_back(T);
    } else {
      cin >> t >> v;
      Lef = v;
      Rit = v;
      Ans.clear();
      for (lev = t - 1; lev < n; lev++) {
        for (j = 0; j < Level[lev].size(); j++) {
          T = Level[lev][j];
          if ((Lef >= T[0] && Lef <= T[1]) || (Rit >= T[0] && Rit <= T[1]) ||
              (Lef < T[0] && Rit > T[1])) {
            Ans.insert(T[2]);
          }
        }
        Lef = Left(Lef);
        r = Rit;
        Rit = Left(Rit);
        if (C.find(r) != C.end()) {
          Rit += 1;
        }
      }
      cout << Ans.size() << endl;
      Ans.clear();
    }
  }
  return 0;
}
