#include <bits/stdc++.h>
using namespace std;
int n, m, temp, t, l, r, x, y;
struct node {
  int l, r, val;
};
vector<node> q[7004];
int Left[200000 + 5], Right[200000 + 5];
void pre() {
  int now = 0, cnt = 0;
  for (int i = 1; i <= 200000; i++) {
    now++;
    if ((1 << cnt) == i) {
      Left[i] = now, Right[i] = now + 1;
      now++, cnt++;
    } else
      Left[i] = now, Right[i] = now;
  }
}
int solve(int dep, int l, int r) {
  set<int> e;
  for (int i = dep; i <= n; i++) {
    for (int j = 0; j < q[i].size(); j++) {
      if (q[i][j].r >= l && q[i][j].l <= r) e.insert(q[i][j].val);
    }
    l = Left[l], r = Right[r];
  }
  return e.size();
}
int main() {
  pre();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &temp);
    if (temp == 1) {
      scanf("%d%d%d%d", &t, &l, &r, &x);
      q[t].push_back(node{l, r, x});
    } else {
      scanf("%d%d", &x, &y);
      printf("%d\n", solve(x, y, y));
    }
  }
  return 0;
}
