#include <bits/stdc++.h>
using namespace std;
const int maxn = 7e3 + 2;
bool flag = true;
int n, m;
vector<pair<pair<int, int>, int> > level[maxn];
set<int> se;
int LOG(int x) {
  if (x == 1) return 0;
  if (x & 1) flag = false;
  return 1 + LOG(x / 2);
}
void doIt(int lvl, int l, int r) {
  for (int i = 0; i < level[lvl].size(); i++)
    if ((level[lvl][i].first.first < l && level[lvl][i].first.second >= l) ||
        (level[lvl][i].first.first >= l && level[lvl][i].first.first <= r))
      se.insert(level[lvl][i].second);
  if (lvl == n) return;
  int x = LOG(l);
  flag == true ? l = l + x : l = l + x + 1;
  flag = true;
  x = LOG(r);
  r = r + x + 1;
  flag = true;
  doIt(lvl + 1, l, r);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int t;
    scanf("%i", &t);
    if (t == 1) {
      int lvl, l, r, x;
      scanf("%i%i%i%i", &lvl, &l, &r, &x);
      level[lvl].push_back(make_pair(make_pair(l, r), x));
    } else {
      int lvl, pos;
      scanf("%i%i", &lvl, &pos);
      doIt(lvl, pos, pos);
      printf("%i\n", (int)se.size());
      se.clear();
    }
  }
  return 0;
}
