#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x + _y;
  if (_ >= _mod) _ -= _mod;
  return _;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x - _y;
  if (_ < 0) _ += _mod;
  return _;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x * _y;
  if (_ >= _mod) _ %= _mod;
  return _;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1ll;
  long long _tmp = mypow(_a, _x / 2, _mod);
  _tmp = mul(_tmp, _tmp, _mod);
  if (_x & 1) _tmp = mul(_tmp, _a, _mod);
  return _tmp;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0ll;
  long long _tmp = mymul(_a, _x / 2, _mod);
  _tmp = add(_tmp, _tmp, _mod);
  if (_x & 1) _tmp = add(_tmp, _a, _mod);
  return _tmp;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
int l[1010101];
int r[1010101];
void build() {
  int cnt = 0;
  for (int i = 1; i < 1010101; i++) {
    l[i] = r[i] = ++cnt;
    if (i == (i & (-i))) r[i] = ++cnt;
  }
}
int tag[1010101], stmp;
int n, m;
vector<tuple<int, int, int> > v[7777];
void init() {
  n = getint();
  m = getint();
}
void solve() {
  while (m--) {
    int cmd = getint();
    if (cmd == 1) {
      int t = getint();
      int ql = getint();
      int qr = getint();
      int qx = getint();
      v[t].push_back(make_tuple(ql, qr, qx));
    } else {
      int t = getint();
      int ql = getint();
      int qr = ql;
      int ans = 0;
      stmp++;
      for (int i = t; i <= n; i++) {
        for (auto tp : v[i]) {
          if (max(ql, get<0>(tp)) <= min(qr, get<1>(tp))) {
            if (tag[get<2>(tp)] != stmp) {
              tag[get<2>(tp)] = stmp;
              ans++;
            }
          }
        }
        ql = l[ql];
        qr = r[qr];
      }
      printf("%d\n", ans);
    }
  }
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
