#include <bits/stdc++.h>
using namespace std;
struct three {
  int l, r, x;
};
vector<three> intervals[7010];
int N, cnt[7010], M, ar[110001];
vector<vector<int> > lef, righ;
void gen();
int main() {
  ar[1] = 0;
  ar[2] = 1;
  for (int i = 3; i <= 110000; i++)
    ar[i] = ar[i - 1] + (((i - 1) & (i - 2)) == 0);
  scanf("%d %d", &N, &M);
  while (M--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int t, l, r, x;
      scanf("%d %d %d %d", &t, &l, &r, &x);
      intervals[t].push_back((three){l, r, x});
    } else {
      int t, p;
      scanf("%d %d", &t, &p);
      set<int> ans;
      int l = p, r = p;
      for (int i = t; i <= N; i++) {
        for (typeof((intervals[i]).begin()) it = (intervals[i]).begin();
             it != (intervals[i]).end(); it++) {
          if (!(l > it->r || r < it->l)) ans.insert(it->x);
        }
        l = ar[l] * 2 + (l - 1 - ar[l]) + 1;
        r = ar[r] * 2 + (r - 1 - ar[r]) + 1 + ((r & (r - 1)) == 0);
      }
      printf("%d\n", ans.size());
    }
  }
  return 0;
}
void gen() {
  N = 1000;
  cnt[1] = 1;
  lef.resize(N + 1);
  righ.resize(N + 1);
  int total = 1;
  for (int level = 1; level < N; level = level + 1) {
    cnt[level + 1] = 0;
    lef[level].push_back(-1);
    righ[level].push_back(-1);
    for (int position = 1; position <= cnt[level]; position = position + 1) {
      if ((position & (position - 1)) == 0) {
        lef[level].push_back(cnt[level + 1] + 1);
        righ[level].push_back(cnt[level + 1] + 2);
        cnt[level + 1] = cnt[level + 1] + 2;
      } else {
        righ[level].push_back(cnt[level + 1] + 1);
        lef[level].push_back(-1);
        cnt[level + 1] = cnt[level + 1] + 1;
      }
    }
    total += cnt[level + 1];
  }
  printf("%d %d\n", total, cnt[N - 1]);
}
