#include <bits/stdc++.h>
using namespace std;
enum { MAXPOS = 110500, MAXBYTE = 20, MAXN = 7070 };
int q_level[MAXN], q_left[MAXN], q_right[MAXN], q_value[MAXN];
int jump_up[MAXBYTE][MAXPOS], jump_low[MAXBYTE][MAXPOS];
int high[MAXPOS];
void init() {
  for (int i = 0; (1 << i) < MAXPOS; i++) high[1 << i] = 1;
  for (int i = 2; i < MAXPOS; i++) {
    high[i] += high[i - 1];
  }
  for (int i = 1; i < MAXPOS; i++) {
    jump_up[0][i] = i + high[i];
    jump_low[0][i] = i + high[i] - !(i & (i - 1));
  }
  for (int i = 1; i < MAXBYTE; i++) {
    for (int j = 1; j < MAXPOS; j++) {
      if (jump_up[i - 1][j] < MAXPOS) {
        jump_up[i][j] = jump_up[i - 1][jump_up[i - 1][j]];
      }
      if (jump_low[i - 1][j] < MAXPOS) {
        jump_low[i][j] = jump_low[i - 1][jump_low[i - 1][j]];
      }
    }
  }
}
inline int get_left(int start, int jumps) {
  if (jumps == 0) return start;
  for (int i = MAXBYTE - 1; i >= 0; i--) {
    if (jumps >= (1 << i)) {
      jumps -= (1 << i);
      start = jump_low[i][start];
    }
  }
  return start;
}
inline int get_right(int start, int jumps) {
  if (jumps == 0) return start;
  for (int i = MAXBYTE - 1; i >= 0; i--) {
    if (jumps >= (1 << i)) {
      jumps -= (1 << i);
      start = jump_up[i][start];
    }
  }
  return start;
}
int main() {
  init();
  int n, m;
  scanf("%d %d", &n, &m);
  int q_cnt = 0;
  for (int i = 0; i < m; i++) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d %d %d", &q_level[q_cnt], &q_left[q_cnt], &q_right[q_cnt],
            &q_value[q_cnt]);
      q_cnt++;
    } else {
      int level, position;
      scanf("%d %d", &level, &position);
      set<int> subtree;
      for (int j = 0; j < q_cnt; j++) {
        if (q_level[j] < level) continue;
        int left = get_left(position, q_level[j] - level);
        int right = get_right(position, q_level[j] - level);
        if (max(left, q_left[j]) <= min(right, q_right[j]))
          subtree.insert(q_value[j]);
      }
      printf("%d\n", (int)subtree.size());
    }
  }
  return 0;
}
