#include <bits/stdc++.h>
using namespace std;
const int maxN = 7002;
struct node {
  int lr;
  int x, ind, pl;
};
int type[maxN], lr[maxN][2], n;
vector<node> timeLine[maxN];
set<int> ans;
int lg(long long v) {
  int k = 0;
  while ((1 << k) < v) k++;
  return k;
}
void count(int n) {
  long long a[maxN], sum[maxN];
  a[1] = sum[1] = 1;
  for (int i = 2; i < n; i++) {
    a[i] = a[i - 1] + lg(a[i - 1]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 6500; i < 7000; i++)
    cerr << i << " : " << a[i] << ", " << sum[i] << endl;
}
bool cmp(node l, node r) { return l.pl < r.pl; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    type[i] = t;
    if (t == 1) {
      int t, lll, rr, x;
      cin >> t >> lll >> rr >> x;
      node a, b;
      a.ind = b.ind = i;
      a.lr = rr;
      b.lr = lll;
      a.pl = lll;
      b.pl = rr;
      a.x = b.x = x;
      timeLine[t].push_back(a);
      timeLine[t].push_back(b);
    } else {
      int t, v;
      cin >> t >> v;
      int lll = v, rr = v;
      ans.clear();
      for (int j = t; j <= n; j++) {
        for (int k = 0; k < timeLine[j].size(); k++)
          if ((timeLine[j][k].pl >= lll && timeLine[j][k].pl <= rr) ||
              (timeLine[j][k].pl < lll && timeLine[j][k].lr > rr))
            ans.insert(timeLine[j][k].x);
        int lgl = lg(lll);
        int lgr = lg(rr);
        lll = lll + lgl;
        if (1 << (lgr) == rr)
          rr = rr + lgr + 1;
        else
          rr = rr + lgr;
      }
      cout << ans.size() << endl;
    }
  }
}
