#include <bits/stdc++.h>
using namespace std;
int L[200001], R[200001];
struct node {
  int l, r, v;
  node() {}
  node(int a, int b, int c) : l(a), r(b), v(c) {}
};
vector<node> ope[7001];
set<int> s;
int n, m;
bool cross(int a, int b, int l, int r) {
  if (l > b || a > r) return false;
  return true;
}
int main() {
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  int t = 1, a = 1, con = 1;
  while (t < 200001) {
    if (con == a)
      L[con] = t++, R[con] = t++, a = (a << 1);
    else
      R[con] = t++;
    con++;
  }
  while (~scanf("%d%d", &n, &m)) {
    for (int i = (1); i <= (n); ++i) ope[i].clear();
    s.clear();
    while (m--) {
      int x, l, r, v;
      scanf("%d", &x);
      if (x == 1) {
        scanf("%d%d%d%d", &x, &l, &r, &v);
        ope[x].push_back(node(l, r, v));
      } else {
        scanf("%d%d", &v, &l);
        int p = l, q = l;
        for (int i = (v); i <= (n); ++i) {
          for (int j = 0; j < (ope[i].size()); ++j) {
            if (cross(p, q, ope[i][j].l, ope[i][j].r)) s.insert(ope[i][j].v);
          }
          if (L[p] != -1)
            p = L[p];
          else
            p = R[p];
          q = R[q];
        }
        cout << s.size() << endl;
        s.clear();
      }
    }
  }
  return 0;
}
