#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
struct Query {
  int l, r, x;
  Query() {}
  Query(int ll, int rr, int xx) { l = ll, r = rr, x = xx; }
};
vector<Query> q[N];
int lson[N], rson[N];
void init() {
  int cnt = 0, p = 1;
  for (int i = 1; i < N; ++i) {
    if ((1 << cnt) == i) {
      cnt++;
      lson[i] = p++;
    } else {
      lson[i] = -1;
    }
    rson[i] = p++;
  }
}
bool ok(int x1, int y1, int x2, int y2) {
  if (x1 > y2 || x2 > y1) return false;
  return true;
}
void solve(int k, int x) {
  set<int> s;
  int l = x, r = x;
  for (int i = k; i < n + 1; ++i) {
    for (int j = 0; j < (int)q[i].size(); ++j) {
      if (ok(l, r, q[i][j].l, q[i][j].r)) {
        s.insert(q[i][j].x);
      }
    }
    if (lson[l] != -1)
      l = lson[l];
    else
      l = rson[l];
    r = rson[r];
  }
  printf("%d\n", (int)s.size());
}
int main() {
  init();
  int op, k, l, r, x;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < m + 1; ++i) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d%d", &k, &l, &r, &x);
      q[k].push_back(Query(l, r, x));
    } else {
      scanf("%d%d", &k, &x);
      solve(k, x);
    }
  }
  return 0;
}
