#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
const int inf = (int)(1e9) * 2;
struct segment_tree {
  int limit[N * 4], tag[N * 4];
  void buildtree(int u, int l, int r) {
    tag[u] = -1, limit[u] = inf;
    if (l == r) return;
    int mid = l + r >> 1;
    buildtree((u << 1), l, mid), buildtree(((u << 1) + 1), mid + 1, r);
  }
  void pushdown(int u, int l, int r) {
    if (tag[u] == -1) return;
    if (l == r) {
      tag[u] = -1;
      return;
    }
    if (tag[(u << 1)] == -1)
      tag[(u << 1)] = tag[u];
    else
      tag[(u << 1)] = min(tag[(u << 1)], tag[u]);
    if (tag[((u << 1) + 1)] == -1)
      tag[((u << 1) + 1)] = tag[u];
    else
      tag[((u << 1) + 1)] = min(tag[((u << 1) + 1)], tag[u]);
    limit[(u << 1)] = min(tag[(u << 1)], limit[(u << 1)]),
                limit[((u << 1) + 1)] =
                    min(tag[((u << 1) + 1)], limit[((u << 1) + 1)]);
    tag[u] = -1;
  }
  void modify(int u, int l, int r, int f, int t, int val) {
    pushdown(u, l, r);
    if (l >= f && r <= t) {
      if (tag[u] == -1)
        tag[u] = val;
      else
        tag[u] = min(tag[u], val);
      limit[u] = min(limit[u], val);
      return;
    }
    int mid = l + r >> 1;
    if (f <= mid) modify((u << 1), l, mid, f, t, val);
    if (t > mid) modify(((u << 1) + 1), mid + 1, r, f, t, val);
    limit[u] = min(limit[(u << 1)], limit[((u << 1) + 1)]);
  }
  int query(int u, int l, int r, int t) {
    pushdown(u, l, r);
    if (l == r) return limit[u];
    int mid = l + r >> 1;
    if (t <= mid)
      return query((u << 1), l, mid, t);
    else
      return query(((u << 1) + 1), mid + 1, r, t);
  }
} TU, TL;
int xd[N], dif;
struct question {
  char ch[5];
  int x, y;
} ques[N];
int uf[N], lf[N];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%s", &ques[i].y, &ques[i].x, ques[i].ch);
    xd[i] = ques[i].x;
  }
  sort(xd + 1, xd + 1 + q);
  dif = unique(xd + 1, xd + 1 + q) - xd - 1;
  TU.buildtree(1, 1, dif), TL.buildtree(1, 1, dif);
  memset(uf, 0, sizeof uf);
  memset(lf, 0, sizeof lf);
  for (int i = 1; i <= q; i++) {
    int id = lower_bound(xd + 1, xd + 1 + dif, ques[i].x) - xd;
    int x = ques[i].x, y = ques[i].y;
    if (ques[i].ch[0] == 'U') {
      if (!uf[id])
        uf[id] = 1;
      else {
        printf("0\n");
        continue;
      }
      int ans = min(x, max(TU.query(1, 1, dif, id) - (n - x), 0));
      printf("%d\n", ans);
      int r = upper_bound(xd + 1, xd + 1 + dif, x) - xd;
      int l = lower_bound(xd + 1, xd + 1 + dif, x - ans + 1) - xd;
      if (r - 1 >= l) TL.modify(1, 1, dif, l, r - 1, n - y);
    } else {
      if (!lf[id])
        lf[id] = 1;
      else {
        printf("0\n");
        continue;
      }
      int ans = min(y, max(TL.query(1, 1, dif, id) - (n - y), 0));
      printf("%d\n", ans);
      int r = upper_bound(xd + 1, xd + 1 + dif, x + ans - 1) - xd;
      int l = lower_bound(xd + 1, xd + 1 + dif, x) - xd;
      if (r - 1 >= l) TU.modify(1, 1, dif, l, r - 1, n - x);
    }
  }
  return 0;
}
