#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, x;
};
set<int> s;
vector<node> v[10010];
struct kk {
  int l, r;
} se[200000];
int main() {
  int n, m;
  cin >> n >> m;
  int p = 3;
  se[1].l = 1;
  se[1].r = 2;
  int cnt = 1;
  for (int i = 2; i <= 200000; i++) {
    if ((i >> cnt) == 1) {
      cnt++;
      se[i].l = p++;
      se[i].r = p++;
    } else {
      se[i].l = -1;
      se[i].r = p++;
    }
  }
  for (int i = 0; i < m; i++) {
    int act;
    cin >> act;
    if (act == 1) {
      int lev, f, t, x;
      cin >> lev >> f >> t >> x;
      v[lev].push_back((node){f, t, x});
    } else {
      int level, pos;
      cin >> level >> pos;
      int l = pos, r = pos;
      s.clear();
      for (int j = level; j <= n; j++) {
        for (int k = 0; k < v[j].size(); k++) {
          if (l <= v[j][k].r && r >= v[j][k].l) {
            s.insert(v[j][k].x);
          }
        }
        if (se[l].l == -1) {
          l = se[l].r;
        } else {
          l = se[l].l;
        }
        r = se[r].r;
      }
      cout << s.size() << endl;
    }
  }
}
