#include <bits/stdc++.h>
using namespace std;
int pww(int x) {
  int cnt = 0;
  while (x) {
    x /= 2;
    cnt++;
  }
  return cnt;
}
int f(int lev) {
  if (lev == 1) return 1;
  int x = f(lev - 1);
  return x + pww(x);
}
const int MAX = 109315;
int Left[MAX + 8], Right[MAX + 8];
int Q[7008][5];
int used[1000008];
int L[7008], R[7008];
int main() {
  int next = 1, n, q;
  for (int i = 1; i <= MAX; i++) {
    if ((i & (i - 1)) == 0) {
      Left[i] = next++, Right[i] = next++;
    } else
      Left[i] = Right[i] = next++;
  }
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> Q[i][0];
    if (Q[i][0] == 1)
      cin >> Q[i][1] >> Q[i][2] >> Q[i][3] >> Q[i][4];
    else
      cin >> Q[i][1] >> Q[i][2];
  }
  for (int i = 0; i < q; i++) {
    if (Q[i][0] == 2) {
      memset(L, -1, sizeof L);
      memset(R, -1, sizeof R);
      int level = Q[i][1], pos = Q[i][2];
      L[level] = R[level] = pos;
      for (int p = level + 1; p <= n; p++) {
        L[p] = Left[L[p - 1]];
        R[p] = Right[R[p - 1]];
      }
      int ans = 0;
      for (int j = 0; j < i; j++) {
        if (Q[j][0] == 1) {
          int t = Q[j][1], l = Q[j][2], r = Q[j][3], x = Q[j][4];
          if (L[t] <= r && R[t] >= l && !used[x]) {
            ans++;
            used[x] = true;
          }
        }
      }
      for (int j = 0; j < i; j++)
        if (Q[j][0] == 1) used[Q[j][4]] = false;
      cout << ans << endl;
    }
  }
  return 0;
}
