#include <bits/stdc++.h>
using namespace std;
template <typename T0, typename T1>
std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) {
  for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {
    os << p->first << ": " << p->second << " ";
  }
  return os;
}
template <typename T0, typename T1>
std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) {
  os << v.first << ": " << v.second << " ";
  return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const vector<T>& v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << " ";
  }
  return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << endl;
  }
  return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const set<T>& v) {
  vector<T> tmp(v.begin(), v.end());
  os << tmp;
  return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const deque<T>& v) {
  vector<T> tmp(v.begin(), v.end());
  os << tmp;
  return os;
}
int chL[110000];
int chR[110000];
int rL[7007];
int rR[7007];
int T[7007];
int L[7007];
int R[7007];
int X[7007];
int main() {
  ios::sync_with_stdio(false);
  long long N, M;
  long long type, t, v;
  while (cin >> N >> M) {
    int cs = 1;
    for (int i = 0, _n = (110000); (i) < (int)_n; ++i) {
      int ch = (__builtin_popcount(i + 1) == 1) ? 2 : 1;
      chL[i + 1] = ch == 2 ? cs++ : -1;
      chR[i + 1] = cs++;
    }
    int hints = 0;
    for (int i = 0, _n = (M); (i) < (int)_n; ++i) {
      cin >> type;
      if (type == 1) {
        cin >> T[hints] >> L[hints] >> R[hints] >> X[hints];
        hints++;
      } else {
        cin >> t >> v;
        for (int j = 0, _n = (t); (j) < (int)_n; ++j) rL[j] = rR[j] = -1;
        rL[t] = rR[t] = v;
        for (int j = (int)t, _b = (int)(N); (j) < _b; ++j) {
          rL[j + 1] = chL[rL[j]] == -1 ? chR[rL[j]] : chL[rL[j]];
          rR[j + 1] = chR[rR[j]];
        }
        map<int, int> ma;
        for (int hi = 0, _n = (hints); (hi) < (int)_n; ++hi) {
          if (rL[T[hi]] == -1) continue;
          bool in = !(R[hi] < rL[T[hi]] || rR[T[hi]] < L[hi]);
          if (in) ma[X[hi]] = 1;
        }
        cout << ma.size() << endl;
      }
    }
  }
  return 0;
}
