#include <bits/stdc++.h>
using namespace std;
const int MAXN = 7003;
const int MAX = 2 * 1e6 + 6;
vector<pair<pair<int, int>, int> > V[MAXN];
bool marked[MAX];
int left2[MAX], right2[MAX];
bool pow2(int p) {
  while ((p % 2) == 0) p /= 2;
  return (p == 1);
}
int main() {
  int n, m;
  cin >> n >> m;
  int cnt = 1;
  for (int i = 1; i < MAX; i++) {
    if (pow2(i)) {
      left2[i] = cnt;
      right2[i] = cnt + 1;
      cnt++;
      cnt++;
    } else {
      left2[i] = right2[i] = cnt;
      cnt++;
    }
  }
  for (int i = 0; i < m; i++) {
    int c;
    cin >> c;
    if (c == 1) {
      int t, l, r, x;
      cin >> t >> l >> r >> x;
      V[t].push_back(pair<pair<int, int>, int>(pair<int, int>(l, r), x));
    } else {
      int t, v;
      cin >> t >> v;
      int L = v, R = v;
      int ans = 0;
      for (int lev = t; lev <= n; lev++) {
        for (int k = 0; k < (int)V[lev].size(); k++) {
          int x = V[lev][k].second;
          bool b =
              (R >= V[lev][k].first.first) && (L <= V[lev][k].first.second);
          if (!marked[x] && b) ans++, marked[x] = true;
        }
        L = left2[L];
        R = right2[R];
      }
      for (int lev = t; lev <= n; lev++) {
        for (int k = 0; k < (int)V[lev].size(); k++)
          marked[V[lev][k].second] = false;
        L = left2[L];
        R = right2[R];
      }
      cout << ans << endl;
    }
  }
  return 0;
}
