#include <bits/stdc++.h>
using namespace std;
const int N = 7010, M = 200010, MAX = 200000, TOT = 1000010;
struct data {
  int t, l, r, x;
} dat[N];
int n, m, lg[M], rec[N], cnt, tot, l[N], r[N];
bool vis[TOT];
void prework() {
  lg[1] = 1;
  for (int i = 2, j = 1; i <= MAX; ++i) {
    lg[i] = lg[i - 1];
    if (i == (1 << j)) ++lg[i], ++j;
  }
}
int solve(int t, int b) {
  int ans = 0, s;
  l[t] = b - 1, r[t] = b;
  for (int i = t + 1; i <= n; ++i) {
    l[i] = l[i - 1] + lg[l[i - 1]];
    r[i] = r[i - 1] + lg[r[i - 1]];
  }
  for (int i = 1; i <= cnt; ++i)
    if (dat[i].t >= t) {
      s = dat[i].t;
      if (((dat[i].l) > (l[s]) && (dat[i].l) <= (r[s])) ||
          ((dat[i].r) > (l[s]) && (dat[i].r) <= (r[s])) ||
          (dat[i].l <= l[s] && dat[i].r > r[s])) {
        if (!vis[dat[i].x]) ++ans, rec[++tot] = dat[i].x;
        vis[dat[i].x] = 1;
      }
    }
  while (tot) {
    vis[rec[tot--]] = 0;
  }
  return ans;
}
int main() {
  int tp, a, b, c, d;
  scanf("%d%d", &n, &m);
  prework();
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &tp);
    if (tp & 1) {
      scanf("%d%d%d%d", &a, &b, &c, &d);
      dat[++cnt] = (data){a, b, c, d};
    } else {
      scanf("%d%d", &a, &b);
      printf("%d\n", solve(a, b));
    }
  }
  return 0;
}
