#include <bits/stdc++.h>
using namespace std;
struct qry {
  int x, y;
  char op;
};
int c[2][800010];
int N, st;
int query(int x, int n = 1, int l = 0, int r = N) {
  if (l == r)
    return c[st][n];
  else {
    if (c[st][n]) {
      c[st][2 * n] = max(c[st][2 * n], c[st][n]);
      c[st][2 * n + 1] = max(c[st][2 * n + 1], c[st][n]);
      c[st][n] = 0;
    }
    int m = (l + r) / 2;
    if (x <= m)
      return query(x, 2 * n, l, m);
    else
      return query(x, 2 * n + 1, m + 1, r);
  }
}
void update(int x, int y, int v, int n = 1, int l = 0, int r = N) {
  if (x <= l && r <= y)
    c[st][n] = max(c[st][n], v);
  else {
    int m = (l + r) / 2;
    if (c[st][n]) {
      c[st][2 * n] = max(c[st][n], c[st][2 * n]);
      c[st][2 * n + 1] = max(c[st][n], c[st][2 * n + 1]);
      c[st][n] = 0;
    }
    if (y > m) update(x, y, v, 2 * n + 1, m + 1, r);
    if (x <= m) update(x, y, v, 2 * n, l, m);
  }
}
qry qrs[200010];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  vector<int> UP, LF;
  for (int i = 0; i < q; i++) {
    scanf("%d%d%c%c", &qrs[i].x, &qrs[i].y, &qrs[i].op, &qrs[i].op);
    if (qrs[i].op == 'U')
      UP.push_back(qrs[i].x);
    else
      LF.push_back(qrs[i].y);
  }
  sort(UP.begin(), UP.end());
  sort(LF.begin(), LF.end());
  UP.resize(unique(UP.begin(), UP.end()) - UP.begin());
  LF.resize(unique(LF.begin(), LF.end()) - LF.begin());
  int up = UP.size();
  int lf = LF.size();
  for (int i = 0; i < q; i++) {
    if (qrs[i].op == 'U') {
      int id = lower_bound(UP.begin(), UP.end(), qrs[i].x) - UP.begin();
      N = up;
      st = 0;
      int te = query(id);
      update(id, id, qrs[i].y);
      printf("%d\n", qrs[i].y - te);
      int l = upper_bound(LF.begin(), LF.end(), te) - LF.begin();
      int r = upper_bound(LF.begin(), LF.end(), qrs[i].y) - LF.begin();
      N = lf;
      st = 1;
      if (r > l) update(l, r - 1, qrs[i].x);
    } else {
      int id = lower_bound(LF.begin(), LF.end(), qrs[i].y) - LF.begin();
      N = lf;
      st = 1;
      int te = query(id);
      update(id, id, qrs[i].x);
      printf("%d\n", qrs[i].x - te);
      int l = upper_bound(UP.begin(), UP.end(), te) - UP.begin();
      int r = upper_bound(UP.begin(), UP.end(), qrs[i].x) - UP.begin();
      N = up;
      st = 0;
      if (r > l) update(l, r - 1, qrs[i].y);
    }
  }
}
