#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
using namespace std;
map<int, int> ma1;
map<int, int> ma2;
vector<pair<pair<int, int>, char> > v;
vector<int> allQx, allQy;
int n, q;
int tree[4 * 200011][2];
int lazy[4 * 200011][2];
struct node {
  int l, r, id, k;
  node() {}
  node(int l_, int r_, int id_, int _k) {
    l = l_;
    r = r_;
    id = id_;
    k = _k;
    lazy_update();
  }
  node left() { return node(l, (l + r) / 2, 2 * id, k); }
  node right() { return node((l + r) / 2 + 1, r, 2 * id + 1, k); }
  void lazy_update() {
    if (lazy[id][k] == 0) return;
    if (l != r) {
      lazy[2 * id][k] = max(lazy[id][k], lazy[2 * id][k]);
      lazy[2 * id + 1][k] = max(lazy[id][k], lazy[2 * id + 1][k]);
    }
    tree[id][k] = max(tree[id][k], lazy[id][k]);
    lazy[id][k] = 0;
  }
  int query(int s, int e, int k) {
    if (r < s or e < l) return 0;
    if (s <= l and r <= e) return tree[id][k];
    return max(left().query(s, e, k), right().query(s, e, k));
  }
  void update(int s, int e, int x, int k) {
    if (r < s or e < l) return;
    if (s <= l and r <= e) {
      lazy[id][k] = max(lazy[id][k], x);
      lazy_update();
      return;
    }
    left().update(s, e, x, k);
    right().update(s, e, x, k);
    tree[id][k] = max(tree[2 * id][k], tree[2 * id + 1][k]);
  }
};
void solve() {
  int c = 1;
  scanf("%d", &n);
  scanf("%d", &q);
  allQx.push_back(0);
  allQy.push_back(0);
  for (int i = 1; i <= q; i++) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    v.push_back(make_pair(make_pair(x, y), c));
    allQx.push_back(x);
    allQy.push_back(y);
  }
  allQx.push_back(n);
  allQy.push_back(n);
  sort(allQx.begin(), allQx.end());
  sort(allQy.begin(), allQy.end());
  for (int i = 0; i < allQx.size(); i++) {
    if (ma1.find(allQx[i]) == ma1.end()) {
      ma1[allQx[i]] = c++;
    }
  }
  c = 1;
  for (int i = 0; i < allQy.size(); i++) {
    if (ma2.find(allQy[i]) == ma2.end()) {
      ma2[allQy[i]] = c++;
    }
  }
  node R(1, q, 1, 0);
  node C(1, q, 1, 1);
  for (int i = 0; i < v.size(); i++) {
    char type = v[i].second;
    if (type == 'U') {
      int x = R.query(ma1[v[i].first.first], ma1[v[i].first.first], 0);
      C.update(ma2[x], ma2[v[i].first.second], v[i].first.first, 1);
      R.update(ma1[v[i].first.first], ma1[v[i].first.first], v[i].first.second,
               0);
      printf("%d", v[i].first.second - x);
      printf("\n");
    } else {
      int x = C.query(ma2[v[i].first.second], ma2[v[i].first.second], 1);
      R.update(ma1[x], ma1[v[i].first.first], v[i].first.second, 0);
      C.update(ma2[v[i].first.second], ma2[v[i].first.second], v[i].first.first,
               1);
      printf("%d", v[i].first.first - x);
      printf("\n");
    }
  }
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
