#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
using namespace std;
const int N = 7005;
const int M = 200000;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
namespace FastIO {
template <typename tp>
inline void read(tp& x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
template <typename tp>
inline void write(tp x) {
  if (x == 0) return (void)(putchar('0'));
  if (x < 0) putchar('-'), x = -x;
  long long pr[20];
  register long long cnt = 0;
  for (; x; x /= 10) pr[++cnt] = x % 10;
  while (cnt) putchar(pr[cnt--] + '0');
}
template <typename tp>
inline void writeln(tp x) {
  write(x);
  putchar('\n');
}
}  // namespace FastIO
using namespace FastIO;
struct line {
  int l, r, val;
  line() {}
  line(int l, int r, int val) {
    this->l = l;
    this->r = r;
    this->val = val;
  }
};
int n, m, lx[M], ly[M];
vector<line> xx[N];
int solve(int d, int x, int y) {
  set<int> ans;
  for (int i = d; i <= n; i++) {
    for (int j = 0; j < xx[i].size(); j++) {
      line& c = xx[i][j];
      if (c.l <= y && c.r >= x) ans.insert(c.val);
    }
    x = (lx[x] == -1 ? ly[x] : lx[x]);
    y = ly[y];
  }
  return ans.size();
}
void init() {
  int cnt = 1, p = 3;
  memset(lx, -1, sizeof(lx));
  memset(ly, -1, sizeof(ly));
  lx[1] = 1;
  ly[1] = 2;
  for (int i = 2; i < M; i++) {
    if ((1 << cnt) == i) cnt++, lx[i] = p++;
    ly[i] = p++;
  }
}
int flag, d, x, y, val;
int main() {
  init();
  read(n), read(m);
  for (int i = 0; i < m; i++) {
    read(flag);
    if (flag == 1)
      read(d), read(x), read(y), read(val), xx[d].push_back(line(x, y, val));
    else
      read(d), read(x), writeln(solve(d, x, x));
  }
  return 0;
}
