#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
const long long INF = (1LL << 60);
const int N = 200000 + 100;
int xis[N << 1];
bool vis[N << 1];
struct QUE {
  bool flag;
  int x, y;
} que[N];
struct SegTree {
  int l, r;
  int val;
} tree[2][N << 2];
int use[N << 2];
int k;
void pushup(int p) {
  tree[k][p].val = min(tree[k][p << 1].val, tree[k][p << 1 | 1].val);
}
void build(int p, int l, int r) {
  tree[k][p].l = l;
  tree[k][p].r = r;
  if (l == r) {
    tree[k][p].val = inf;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int p, int pos, int val) {
  if (tree[k][p].l == tree[k][p].r) {
    tree[k][p].val = val;
    return;
  }
  int mid = (tree[k][p].l + tree[k][p].r) >> 1;
  if (pos <= mid) {
    update(p << 1, pos, val);
  } else {
    update(p << 1 | 1, pos, val);
  }
  pushup(p);
}
int tar, val, pos;
int query(int p, int l, int r) {
  if (l <= tree[k][p].l && tree[k][p].r <= r) {
    return tree[k][p].val;
  }
  int mid = (tree[k][p].l + tree[k][p].r) >> 1;
  if (r <= mid) {
    return query(p << 1, l, r);
  } else if (l > mid) {
    return query(p << 1 | 1, l, r);
  } else {
    return min(query(p << 1, l, mid), query(p << 1 | 1, mid + 1, r));
  }
}
void work1(int l, int r) {
  int L = l, R = r, mid;
  while (L <= R) {
    mid = (L + R) >> 1;
    int v = query(1, mid, r);
    if (v <= tar) {
      L = mid + 1;
      pos = mid;
      val = v;
    } else {
      R = mid - 1;
    }
  }
}
void work2(int l, int r) {
  int L = l, R = r, mid;
  while (L <= R) {
    mid = (L + R) >> 1;
    int v = query(1, l, mid);
    if (v <= tar) {
      R = mid - 1;
      pos = mid;
      val = v;
    } else {
      L = mid + 1;
    }
  }
}
char op[4];
int ret;
int main() {
  int n, q;
  while (~scanf("%d%d", &n, &q)) {
    ret = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= q; ++i) {
      scanf("%d%d%s", &que[i].x, &que[i].y, op);
      if (op[0] == 'U') {
        que[i].flag = 0;
      } else {
        que[i].flag = 1;
      }
      swap(que[i].x, que[i].y);
      xis[++ret] = que[i].x;
    }
    sort(xis + 1, xis + 1 + ret);
    ret = unique(xis + 1, xis + 1 + ret) - xis - 1;
    k = 0;
    build(1, 1, ret);
    k = 1;
    build(1, 1, ret);
    for (int i = 1; i <= q; ++i) {
      int x = que[i].x;
      int y = que[i].y;
      int ans = 0;
      int indx = lower_bound(xis + 1, xis + 1 + ret, x) - xis;
      if (vis[indx]) {
        printf("0\n");
        continue;
      }
      val = inf;
      vis[indx] = 1;
      if (que[i].flag == 0) {
        tar = y;
        if (indx == 1) {
          ans = x;
        } else {
          k = 0;
          work1(1, indx - 1);
          if (val <= tar) {
            ans = x - xis[pos];
          } else {
            ans = x;
          }
        }
        k = 1;
        update(1, indx, x - ans + 1);
      } else {
        tar = x;
        if (indx == ret) {
          ans = y;
        } else {
          k = 1;
          work2(indx + 1, ret);
          if (val <= tar) {
            ans = y - (n + 1 - xis[pos]);
          } else {
            ans = y;
          }
        }
        k = 0;
        update(1, indx, y - ans + 1);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
