#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, w = 0;
  register char ch = getchar();
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return w ? -x : x;
}
int n, m, q;
struct BIT {
  int a[5005 << 1][5005];
  inline void clear() { memset(a, 0, sizeof a); }
  inline void modify(int x, int l, int r, int z) {
    register int i, j;
    for (i = x; i; i ^= (i & -i)) {
      for (j = r; j; j ^= (j & -j)) a[i][j] += z;
      for (j = l - 1; j; j ^= (j & -j)) a[i][j] -= z;
    }
  }
  inline int query(int x, int y) {
    register int i, j, res = 0;
    for (i = x; i <= m; i += (i & -i))
      for (j = y; j <= n; j += (j & -j)) res += a[i][j];
    return res;
  }
} tr;
int op[100005], o[100005], x[100005], y[100005], l[100005], ans[100005];
int main() {
  n = read(), q = read();
  m = n << 1;
  register int i;
  for (i = 1; i <= q; ++i) {
    op[i] = read();
    if (op[i] == 1) o[i] = read();
    x[i] = read(), y[i] = read();
    if (op[i] == 1) l[i] = read();
  }
  for (i = 1; i <= q; ++i) {
    if (op[i] == 1) {
      if (o[i] == 1) tr.modify(y[i] - 1, x[i], x[i] + l[i], -1);
      if (o[i] == 2) tr.modify(y[i], x[i], x[i] + l[i], 1);
      if (o[i] == 3) tr.modify(y[i] - 1, x[i] - l[i], x[i], -1);
      if (o[i] == 4) tr.modify(y[i], x[i] - l[i], x[i], 1);
    } else
      ans[i] += tr.query(y[i], x[i]);
  }
  tr.clear();
  for (i = 1; i <= q; ++i) {
    if (op[i] == 1) {
      if (o[i] == 1) tr.modify(x[i] + y[i] + l[i], x[i], x[i] + l[i], 1);
      if (o[i] == 4) tr.modify(x[i] + y[i] - l[i] - 1, x[i] - l[i], x[i], -1);
    } else
      ans[i] += tr.query(x[i] + y[i], x[i]);
  }
  tr.clear();
  for (i = 1; i <= q; ++i) {
    if (op[i] == 1) {
      if (o[i] == 2)
        tr.modify(y[i] - x[i] - l[i] - 1 + n, x[i], x[i] + l[i], -1);
      if (o[i] == 3) tr.modify(y[i] - x[i] + l[i] + n, x[i] - l[i], x[i], 1);
    } else
      ans[i] += tr.query(y[i] - x[i] + n, x[i]);
  }
  for (i = 1; i <= q; ++i)
    if (op[i] == 2) printf("%d\n", ans[i]);
  return 0;
}
