#include <bits/stdc++.h>
using namespace std;
map<int, int> h;
map<int, int> l;
map<int, int>::iterator it;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    char op[5];
    scanf("%d%d%s", &x, &y, op);
    if (op[0] == 'U') {
      int ans = 0;
      it = h.lower_bound(x);
      if (it->first == x) {
        printf("0\n");
        continue;
      }
      if (it == h.end())
        ans = y;
      else
        ans = y - it->second;
      printf("%d\n", ans);
      l[y] = x;
      h[x] = y - ans;
    }
    if (op[0] == 'L') {
      int ans = 0;
      it = l.lower_bound(y);
      if (it->first == y) {
        printf("0\n");
        continue;
      }
      if (it == l.end())
        ans = x;
      else
        ans = x - it->second;
      printf("%d\n", ans);
      h[x] = y;
      l[y] = x - ans;
    }
  }
  return 0;
}
