#include <bits/stdc++.h>
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int MAX = 120000;
const int MAXQ = 7070;
int parent[15][MAX];
int level[MAXQ], L[MAXQ], R[MAXQ], X[MAXQ];
int calc(int v, int d) {
  for (int i = 15 - 1; i >= 0; i--) {
    if (d & (1 << i)) v = parent[i][v];
  }
  return v;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  for (int i = 0; i < MAX; i++) {
    int tmp = 1, next = i;
    while (tmp <= i) {
      next++;
      tmp *= 2;
    }
    parent[0][i] = next;
  }
  for (int i = 0; i < 15 - 1; i++) {
    for (int j = 0; j < MAX; j++) {
      if (parent[i][j] > MAX)
        continue;
      else
        parent[i + 1][j] = parent[i][parent[i][j]];
    }
  }
  int n, m;
  cin >> n >> m;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      cin >> level[cnt] >> L[cnt] >> R[cnt] >> X[cnt];
      cnt++;
    } else {
      int t, v;
      cin >> t >> v;
      set<int> S;
      for (int j = 0; j < cnt; j++) {
        int d = level[j] - t;
        if (d < 0) continue;
        int t1 = calc(v - 1, d), t2 = calc(v, d);
        if (t1 + 1 <= R[j] && L[j] <= t2) S.insert(X[j]);
      }
      cout << S.size() << endl;
    }
  }
  return 0;
}
