#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 7005;
const int M = 110000;
const int mod = 1e9 + 7;
int lft[M], rt[M], n, m;
void init() {
  int go = 1;
  memset(lft, -1, sizeof lft);
  memset(rt, -1, sizeof rt);
  for (int i = 1; i < M; i++) {
    if (i == (i & -i)) {
      lft[i] = go++;
      rt[i] = go++;
    } else
      rt[i] = go++;
  }
}
bool intersect(int l1, int r1, int l2, int r2) {
  return max(l1, l2) <= min(r1, r2);
}
int pos[1000005];
vector<vector<pair<int, pair<int, int>>>> vp;
int L[N], R[N];
int main() {
  init();
  scanf("%d%d", &n, &m);
  memset(pos, -1, sizeof pos);
  while (m--) {
    int tp, t, l, r, x, v;
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d%d%d%d", &t, &l, &r, &x);
      if (pos[x] == -1)
        pos[x] = vp.size(), vp.push_back(vector<pair<int, pair<int, int>>>());
      x = pos[x];
      vp[x].push_back(make_pair(t, make_pair(l, r)));
    } else {
      scanf("%d%d", &t, &v);
      memset(L, -1, sizeof L);
      memset(R, -1, sizeof R);
      int take = v;
      for (int i = t; i <= n; i++) {
        L[i] = take;
        if (~lft[take])
          take = lft[take];
        else
          take = rt[take];
      }
      take = v;
      for (int i = t; i <= n; i++) {
        R[i] = take;
        take = rt[take];
      }
      int ans = 0;
      for (int i = 0; i < vp.size(); i++) {
        for (auto x : vp[i])
          if (intersect(L[x.first], R[x.first], x.second.first,
                        x.second.second)) {
            ans++;
            break;
          }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
