#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, x;
};
vector<node> v[7005];
set<int> s;
int id[8000005][2];
int main() {
  int n, m;
  memset(id, 0, sizeof(id));
  int f = 0;
  int ct = 1;
  for (int i = 1; i <= 8000000; i++) {
    int tr = log(i) / log(2);
    if (i == (1 << f)) {
      f++;
      id[i][0] = ct++;
      id[i][1] = ct++;
    } else {
      id[i][0] = ct++;
    }
  }
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= 7000; i++) v[i].clear();
    for (int k = 0; k < m; k++) {
      int sig;
      scanf("%d", &sig);
      if (sig == 1) {
        int t, l, r, x;
        scanf("%d%d%d%d", &t, &l, &r, &x);
        node tp;
        tp.l = l;
        tp.r = r;
        tp.x = x;
        v[t].push_back(tp);
      } else {
        int t, vv;
        scanf("%d%d", &t, &vv);
        s.clear();
        int l = vv, r = vv;
        for (int i = t; i <= n; i++) {
          int len = v[i].size();
          for (int j = 0; j < len; j++) {
            int ll = v[i][j].l;
            int rr = v[i][j].r;
            int xx = v[i][j].x;
            if (!(ll > r || rr < l)) {
              s.insert(xx);
            }
          }
          l = id[l][0];
          if (id[r][1] == 0) {
            r = id[r][0];
          } else {
            r = id[r][1];
          }
        }
        printf("%d\n", s.size());
      }
    }
  }
}
