#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int maxm = 100005;
int n, q, dir;
int qt[maxm], qd[maxm], qx[maxm], qy[maxm], qlen[maxm], ans[maxm];
namespace Segtree {
const int maxs = maxn * 500;
int tot;
int ls[maxs], rs[maxs], rtx[maxs], rty[maxs], sum[maxs], tots[maxs];
void clear(int cur, int l, int r) {
  tot = 0;
  rtx[cur] = rty[cur] = tots[cur] = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  clear(cur << 1, l, mid);
  clear(cur << 1 | 1, mid + 1, r);
}
void sub_update(int &cur, int l, int r, int vl, int vr) {
  if (vl > vr) return;
  if (!cur) {
    cur = ++tot;
    ls[cur] = rs[cur] = sum[cur] = 0;
  }
  if (l >= vl && r <= vr) {
    sum[cur]++;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= vl) sub_update(ls[cur], l, mid, vl, vr);
  if (mid < vr) sub_update(rs[cur], mid + 1, r, vl, vr);
}
void update(int cur, int l, int r, int vl, int vr, int vx, int vy) {
  if (l >= vl && r <= vr) {
    tots[cur]++;
    sub_update(rtx[cur], 1, n, 1, vx);
    sub_update(rty[cur], 1, n, 1, vy);
    return;
  }
  int mid = l + r >> 1;
  if (mid >= vl) update(cur << 1, l, mid, vl, vr, vx, vy);
  if (mid < vr) update(cur << 1 | 1, mid + 1, r, vl, vr, vx, vy);
}
int sub_query(int cur, int l, int r, int k) {
  if (!cur) return 0;
  int res = sum[cur];
  if (l == r) return res;
  int mid = l + r >> 1;
  if (k <= mid)
    res += sub_query(ls[cur], l, mid, k);
  else
    res += sub_query(rs[cur], mid + 1, r, k);
  return res;
}
int query(int cur, int l, int r, int k, int kx, int ky) {
  int res =
      tots[cur] - sub_query(rtx[cur], 1, n, kx) - sub_query(rty[cur], 1, n, ky);
  if (l == r) return res;
  int mid = l + r >> 1;
  if (k <= mid)
    res += query(cur << 1, l, mid, k, kx, ky);
  else
    res += query(cur << 1 | 1, mid + 1, r, k, kx, ky);
  return res;
}
}  // namespace Segtree
void solve(int dir) {
  Segtree::clear(1, 1, 2 * n);
  for (int i = 1; i <= (q); i++) {
    if (qt[i] == 2) {
      ans[i] += Segtree::query(1, 1, 2 * n, qx[i] + qy[i], qx[i], qy[i]);
    } else if (qd[i] == dir) {
      Segtree::update(1, 1, 2 * n, qx[i] + qy[i], qx[i] + qy[i] + qlen[i],
                      qx[i] - 1, qy[i] - 1);
    }
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= (q); i++) {
    scanf("%d", &qt[i]);
    if (qt[i] == 1)
      scanf("%d%d%d%d", &qd[i], &qx[i], &qy[i], &qlen[i]);
    else
      scanf("%d%d", &qx[i], &qy[i]);
  }
  solve(1);
  for (int i = 1; i <= (q); i++) qy[i] = n - qy[i] + 1;
  solve(2);
  for (int i = 1; i <= (q); i++) qy[i] = n - qy[i] + 1, qx[i] = n - qx[i] + 1;
  solve(3);
  for (int i = 1; i <= (q); i++) qy[i] = n - qy[i] + 1;
  solve(4);
  for (int i = 1; i <= (q); i++)
    if (qt[i] == 2) printf("%d\n", ans[i]);
  return 0;
}
