#include <bits/stdc++.h>
using namespace std;
const int NMAX = 7010;
int N, M, Type, T, L, R, X, V;
vector<pair<pair<int, int>, int> > I[NMAX];
int Log(int X) {
  int Cnt = -1;
  while (X) Cnt++, X /= 2;
  return Cnt + 1;
}
int main() {
  scanf("%i %i", &N, &M);
  for (; M; M--) {
    scanf("%i", &Type);
    if (Type == 1) {
      scanf("%i %i %i %i", &T, &L, &R, &X);
      I[T].push_back(make_pair(make_pair(L, R), X));
    } else {
      scanf("%i %i", &T, &V);
      set<int> S;
      int LeftB = V, RightB = V;
      for (int i = T; i <= N; ++i) {
        for (int j = 0; j < I[i].size(); ++j)
          if (!(I[i][j].first.second < LeftB || I[i][j].first.first > RightB))
            S.insert(I[i][j].second);
        LeftB += Log(LeftB - 1);
        RightB += Log(RightB);
      }
      printf("%i\n", S.size());
    }
  }
}
