#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 2000000000;
long long INFF = 8000000000000000000LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
inline string IntToString(int a) {
  char x[100];
  sprintf(x, "%d", a);
  string s = x;
  return s;
}
inline int StringToInt(string a) {
  char x[100];
  int res;
  strcpy(x, a.c_str());
  sscanf(x, "%d", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
int n, m, type, a, b, c, d;
vector<pair<pair<int, int>, pair<int, int> > > data;
pair<int, int> batas[7005];
int L(int x) {
  if (x == 0) return 0;
  int a = 1;
  int res = 0;
  while (a <= x) {
    ++res;
    a *= 2;
  }
  return res;
  return (int)(log10(x) / log10(2) + 1);
}
int main() {
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d %d %d", &a, &b, &c, &d);
      data.push_back(make_pair(make_pair(a, b), make_pair(c, d)));
    } else {
      set<int> risan;
      risan.clear();
      scanf("%d %d", &a, &b);
      batas[a] = make_pair(b, b);
      for (int(i) = (a + 1); (i) <= (n); ++(i)) {
        batas[i].first = batas[i - 1].first - 1 + L(batas[i - 1].first - 1) + 1;
        batas[i].second = batas[i - 1].second + L(batas[i - 1].second);
      }
      for (int(i) = (0); (i) < ((int)data.size()); ++(i)) {
        if (data[i].first.first < a) continue;
        int t = data[i].first.first;
        int x = data[i].first.second;
        int y = data[i].second.first;
        if (x <= batas[t].first && batas[t].first <= y)
          risan.insert(data[i].second.second);
        else if (x <= batas[t].second && batas[t].second <= y)
          risan.insert(data[i].second.second);
        else if (batas[t].first <= x && x <= batas[t].second)
          risan.insert(data[i].second.second);
        else if (batas[t].first <= y && y <= batas[t].second)
          risan.insert(data[i].second.second);
      }
      printf("%d\n", (int)risan.size());
    }
  }
  return 0;
}
