#include <bits/stdc++.h>
using namespace std;
const int mm = 7009;
int d[mm * 311], l[mm], r[mm], x[mm], vis[mm * 311];
vector<int> level[mm];
int main() {
  d[0] = 0;
  for (int i = 1; i <= 111 * mm - 1; ++i) {
    d[i] = d[i - 1] + 1;
    if ((i & (i - 1)) == 0) ++d[i];
  }
  int n, m;
  while (cin >> n >> m) {
    int res = 0, typ, id;
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i <= mm - 1; ++i) level[i].clear();
    for (int i = 1; i <= m; ++i) {
      cin >> typ;
      if (typ == 1) {
        cin >> id >> l[i] >> r[i] >> x[i];
        level[id].push_back(i);
      } else {
        int t, v, ll, rr, ans;
        cin >> t >> v;
        ++res;
        ans = 0;
        ll = rr = v;
        for (int j = t; j <= n; ++j) {
          int len = level[j].size() - 1;
          for (int k = 0; k <= len; ++k)
            if (ll > r[level[j][k]] || rr < l[level[j][k]])
              continue;
            else {
              if (vis[x[level[j][k]]] != res) {
                vis[x[level[j][k]]] = res;
                ++ans;
              }
            }
          ll = d[ll - 1] + 1;
          rr = d[rr];
        }
        cout << ans << endl;
      }
    }
  }
  return 0;
}
