#include <bits/stdc++.h>
using namespace std;
int ck, n, q;
int dir[120000];
int opt[120000];
int ans[120000];
int pos[120000][2];
struct bit {
  int tag[5200][5200];
  int val[5200][5200];
  inline int query(int x, int y) {
    int ss = 0;
    int yy = y;
    while (x != 0) {
      y = yy;
      while (y != 0) {
        if (tag[x][y] != ck) {
          tag[x][y] = ck;
          val[x][y] = 0;
        }
        ss += val[x][y];
        y -= (y & (-y));
      }
      x -= (x & (-x));
    }
    return ss;
  }
  inline void edit(int x, int y, int va) {
    int yy = y;
    while (x <= n) {
      y = yy;
      while (y <= n) {
        if (tag[x][y] != ck) {
          tag[x][y] = ck;
          val[x][y] = 0;
        }
        val[x][y] += va;
        y += (y & (-y));
      }
      x += (x & (-x));
    }
  }
} sgt;
struct query {
  int x, y, type, comp, id;
} qu[120000], tmp[120000];
int tot, ctot;
inline bool cmp(query x, query y) {
  if (x.comp == y.comp) return x.type < y.type;
  return x.comp > y.comp;
}
inline void solve(int le, int ri) {
  if (le == ri) return;
  int mi = ((le + ri) >> 1), c1 = 0, c2 = 0;
  solve(le, mi);
  solve(mi + 1, ri);
  ctot = 0;
  for (int i = le; i <= mi; i++) {
    if (qu[i].type == 1) {
      c1++;
      ctot++;
      tmp[ctot] = qu[i];
    }
  }
  for (int i = mi + 1; i <= ri; i++) {
    if (qu[i].type == 2) {
      c2++;
      ctot++;
      tmp[ctot] = qu[i];
    }
  }
  if (c1 * c2 == 0) return;
  ck++;
  sort(tmp + 1, tmp + ctot + 1, cmp);
  for (int i = 1; i <= ctot; i++) {
    if (tmp[i].type == 1) {
      sgt.edit(tmp[i].x, tmp[i].y, 1);
    } else {
      ans[tmp[i].id] += sgt.query(tmp[i].x, tmp[i].y);
    }
  }
}
int lee[120000];
inline void work(int di) {
  tot = 0;
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 2 || dir[i] == di) {
      tot++;
      int x1, x2;
      if (di == 1) {
        x1 = pos[i][0];
        x2 = pos[i][1];
      } else if (di == 2) {
        x1 = pos[i][0];
        x2 = n + 1 - pos[i][1];
      } else if (di == 3) {
        x1 = n + 1 - pos[i][0];
        x2 = pos[i][1];
      } else {
        x1 = n + 1 - pos[i][0];
        x2 = n + 1 - pos[i][1];
      }
      qu[tot].x = x1;
      qu[tot].y = x2;
      qu[tot].type = opt[i];
      qu[tot].id = i;
      if (opt[i] == 2) {
        qu[tot].comp = x1 + x2;
      } else {
        qu[tot].comp = x1 + x2 + lee[i];
      }
    }
  }
  solve(1, tot);
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &opt[i]);
    if (opt[i] == 1)
      scanf("%d %d %d %d", &dir[i], &pos[i][0], &pos[i][1], &lee[i]);
    else
      scanf("%d %d", &pos[i][0], &pos[i][1]);
  }
  for (int i = 1; i <= 4; i++) {
    work(i);
  }
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 2) printf("%d\n", ans[i]);
  }
  return 0;
}
