#include <bits/stdc++.h>
using namespace std;
struct S {
  int a, b;
  int x;
};
int n, m;
vector<S> v[7001];
int l[110000];
int r[110000];
short f[1000001];
int main() {
  for (int i = 1, c = 1; i < 110000; ++i) {
    l[i] = c;
    if (!(i & i - 1)) ++c;
    r[i] = c;
    ++c;
  }
  scanf("%d %d", &n, &m);
  for (int mi = 0; mi < m; ++mi) {
    int tp;
    scanf("%d", &tp);
    if (tp == 1) {
      S s;
      int d;
      scanf("%d %d %d %d", &d, &s.a, &s.b, &s.x);
      v[d].push_back(s);
    } else {
      int d, a, b;
      scanf("%d %d", &d, &a);
      b = a;
      int sol = 0;
      for (int i = d; i <= n; ++i) {
        for (int j = 0; j < v[i].size(); ++j) {
          S &r = v[i][j];
          if ((a <= r.a && r.a <= b || r.a <= a && a <= r.b) && f[r.x] != mi) {
            f[r.x] = mi;
            ++sol;
          }
        }
        a = l[a];
        b = r[b];
      }
      printf("%d\n", sol);
    }
  }
  return 0;
}
