#include <bits/stdc++.h>
using namespace std;
const int sz = 1600006;
int n, m;
int co[sz];
typedef struct A {
  int x, y;
  char dir[5];
} AA;
AA t[sz];
bool cmp(AA a, AA b) {
  if (a.x < b.x) return 1;
  return 0;
}
int get_idx(int x) {
  int l = 0, r = 2 * m;
  int mid;
  while (r != l) {
    mid = (l + r) >> 1;
    if (x <= co[mid])
      r = mid;
    else
      l = mid + 1;
  }
  return l;
}
int max(int a, int b) { return (a > b) ? a : b; }
struct SegTree {
  int tr[sz], lazy[sz];
  SegTree() {
    memset(tr, 0, sizeof(tr));
    memset(lazy, 0, sizeof(lazy));
  }
  void up(int r) { tr[r] = max(tr[r << 1], tr[r << 1 | 1]); }
  void down(int L, int mid, int R, int r) {
    lazy[r << 1] = max(lazy[r << 1], lazy[r]);
    lazy[r << 1 | 1] = max(lazy[r << 1 | 1], lazy[r]);
    tr[r << 1] = max(tr[r << 1], lazy[r]);
    tr[r << 1 | 1] = max(tr[r << 1 | 1], lazy[r]);
    lazy[r] = 0;
  }
  void update(int x, int y, int z, int L, int R, int r) {
    if (x <= L && R <= y) {
      lazy[r] = max(lazy[r], z);
      tr[r] = max(tr[r], z);
    } else {
      int mid = (L + R) >> 1;
      if (lazy[r] != 0) {
        down(L, mid, R, r);
      }
      if (x <= mid) update(x, y, z, L, mid, r << 1);
      if (y > mid) update(x, y, z, mid + 1, R, r << 1 | 1);
      up(r);
    }
  }
  int query(int x, int y, int L, int R, int r) {
    if (x <= L && R <= y)
      return tr[r];
    else {
      int maxi = 0;
      int mid = (L + R) >> 1;
      if (lazy[r] != 0) {
        down(L, mid, R, r);
      }
      if (x <= mid) maxi = max(maxi, query(x, y, L, mid, r << 1));
      if (y > mid) maxi = max(maxi, query(x, y, mid + 1, R, r << 1 | 1));
      return maxi;
    }
  }
};
SegTree lf, up;
int main() {
  int i, j, id, q;
  while (scanf("%d %d", &n, &m) != EOF) {
    co[0] = 0;
    j = 1;
    for (i = 0; i < m; i++) {
      scanf("%d %d %s", &t[i].x, &t[i].y, t[i].dir);
      co[j++] = t[i].x;
      co[j++] = t[i].y;
    }
    sort(co, co + 2 * m + 1);
    for (i = 0; i < m; i++) {
      if (t[i].dir[0] == 'U') {
        id = get_idx(t[i].x);
        q = up.query(id, id, 0, 2 * m, 1);
        printf("%d\n", t[i].y - co[q]);
        up.update(id, id, get_idx(t[i].y), 0, 2 * m, 1);
        lf.update(q, get_idx(t[i].y), id, 0, 2 * m, 1);
      } else if (t[i].dir[0] == 'L') {
        id = get_idx(t[i].y);
        q = lf.query(id, id, 0, 2 * m, 1);
        printf("%d\n", t[i].x - co[q]);
        lf.update(id, id, get_idx(t[i].x), 0, 2 * m, 1);
        up.update(q, get_idx(t[i].x), id, 0, 2 * m, 1);
      }
    }
  }
  return 0;
}
