#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long mod = 1000000007LL;
const int maxn = 1 << 18;
int par[maxn], type[maxn];
int t[maxn], l[maxn], r[maxn], x[maxn], v[maxn];
vector<int> ls[7010];
int tree[18][1 << 18];
int calc(int x, int y, int t, int l, int r) {
  for (int i = 20; i >= 0; i--)
    if (t - (1LL << i) >= x) {
      t -= (1LL << i);
      l = tree[i][l];
      r = tree[i][r];
    }
  return x <= t && l <= y && y <= r;
}
void RMQ() {
  int n = 200010;
  for (int i = 0; i < n; i++) tree[0][i] = par[i];
  for (int i = 1; (1LL << i) < n; i++)
    for (int j = 0; j < n; j++) tree[i][j] = tree[i - 1][tree[i - 1][j]];
}
int main() {
  int xx = 0;
  for (int i = 1; i + xx < 200010; i++)
    if (i == (i & (-i)))
      par[i + xx] = par[i + xx + 1] = i, xx++;
    else
      par[i + xx] = i;
  RMQ();
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 1)
      scanf("%d%d%d%d", &t[i], &l[i], &r[i], &x[i]);
    else
      scanf("%d%d", &t[i], &v[i]);
  }
  for (int i = 0; i < m; i++)
    if (type[i] == 2)
      for (int j = 0; j < i; j++)
        if (type[j] == 1)
          if (calc(t[i], v[i], t[j], l[j], r[j])) ls[i].push_back(x[j]);
  for (int i = 0; i < m; i++)
    if (type[i] == 2) {
      sort(ls[i].begin(), ls[i].end());
      int cnt = ls[i].size() ? 1 : 0;
      for (int j = 1; j < ls[i].size(); j++)
        if (ls[i][j] != ls[i][j - 1]) cnt++;
      cout << cnt << endl;
    }
  return 0;
}
