#include <bits/stdc++.h>
using namespace std;
struct node {
  int val;
  node *l, *r;
  node() {
    val = 0;
    l = NULL;
    r = NULL;
  }
};
node *segr, *segc;
void update(node *cur, int l, int r, int x, int y, int val) {
  if (l > r || l > y || r < x) return;
  if (x <= l && r <= y) {
    cur->val = max(cur->val, val);
    return;
  }
  int mid = (l + r) >> 1;
  if (cur->l == NULL) cur->l = new node();
  if (cur->r == NULL) cur->r = new node();
  update(cur->l, l, mid, x, y, val);
  update(cur->r, mid + 1, r, x, y, val);
}
int query(node *cur, int l, int r, int idx) {
  if (cur == NULL || l > idx || l > r || r < idx) return 0;
  if (l == r && l == idx) {
    return cur->val;
  }
  int mid = (l + r) >> 1;
  return max(
      {cur->val, query(cur->l, l, mid, idx), query(cur->r, mid + 1, r, idx)});
}
const int maxn = (int)(1e9);
int main() {
  segr = new node();
  segc = new node();
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 0; i < q; i++) {
    int u, v;
    char c;
    scanf("%d %d %c", &u, &v, &c);
    if (c == 'U') {
      int ma = query(segc, 1, maxn, u);
      printf("%d\n", v - ma);
      update(segr, 1, maxn, ma, v, u);
      update(segc, 1, maxn, u, u, v);
    } else {
      int ma = query(segr, 1, maxn, v);
      printf("%d\n", u - ma);
      update(segc, 1, maxn, ma, u, v);
      update(segr, 1, maxn, v, v, u);
    }
  }
  return 0;
}
