#include <bits/stdc++.h>
using namespace std;
int i, j, k;
struct qr {
  int l;
  int r;
  int x;
};
int pwl(int ind) {
  int p = 1;
  int ans = 0;
  while (p <= ind) {
    p = p * 2;
    ans++;
  }
  return ans;
}
int main() {
  int T = 1;
  ios_base::sync_with_stdio(0);
  int m, n;
  cin >> n >> m;
  vector<vector<qr> > sb(n + 1);
  for (i = 0; i < m; i++) {
    int p;
    cin >> p;
    qr qt;
    if (p == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x;
      qt.l = l;
      qt.r = r;
      qt.x = x;
      sb[t].push_back(qt);
    } else {
      int t, v;
      cin >> t >> v;
      set<int> ans;
      int il = t;
      int lm = v;
      int rm = v;
      while (il <= n) {
        for (j = 0; j < sb[il].size(); j++) {
          qr ot = sb[il][j];
          int l = ot.l;
          int r = ot.r;
          int x = ot.x;
          if ((l <= lm && r >= rm) || (l >= lm && l <= rm) ||
              (r >= lm && r <= rm))
            ans.insert(x);
        }
        il++;
        lm = lm + pwl(lm - 1);
        rm = rm + pwl(rm);
      }
      cout << ans.size() << endl;
    }
  }
  return 0;
}
