#include <bits/stdc++.h>
using namespace std;
const int maxn = 400010;
int cnt, n, m;
int lu[2][maxn << 2];
pair<pair<int, int>, int> Q[maxn], now;
vector<int> V;
void pushdown(int root) {
  for (int i = 0; i < 2; i++)
    if (lu[i][root]) {
      lu[i][root << 1] = max(lu[i][root], lu[i][root << 1]);
      lu[i][root << 1 | 1] = max(lu[i][root], lu[i][root << 1 | 1]);
      lu[i][root] = 0;
    }
}
void update(int l, int r, int root, int L, int R, int val, int flag) {
  if (L <= l && R >= r) {
    lu[flag][root] = max(lu[flag][root], val);
    return;
  }
  pushdown(root);
  int mid = (l + r) >> 1;
  if (L <= mid) update(l, mid, root << 1, L, R, val, flag);
  if (R > mid) update(mid + 1, r, root << 1 | 1, L, R, val, flag);
}
int query(int l, int r, int root, int x, int flag) {
  if (l == r && l == x) {
    return lu[flag][root];
  }
  pushdown(root);
  int mid = (l + r) >> 1;
  if (x <= mid)
    return query(l, mid, root << 1, x, flag);
  else
    return query(mid + 1, r, root << 1 | 1, x, flag);
}
void solve() {
  V.clear();
  V.push_back(0);
  V.push_back(1);
  int x, y;
  char ch[2];
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%s", &x, &y, ch);
    V.push_back(x);
    V.push_back(y);
    if (ch[0] == 'U')
      Q[i] = make_pair(make_pair(x, y), 1);
    else
      Q[i] = make_pair(make_pair(x, y), 0);
  }
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());
  int cnt = V.size();
  memset(lu, 0, sizeof(lu));
  for (int i = 1; i <= m; i++) {
    now = Q[i];
    if (now.second) {
      pair<int, int> g = now.first;
      int x = lower_bound(V.begin(), V.end(), g.first) - V.begin();
      int y = lower_bound(V.begin(), V.end(), g.second) - V.begin();
      int t = query(1, cnt, 1, x, 0);
      printf("%d\n", V[y] - V[t]);
      update(1, cnt, 1, x, x, y, 0);
      update(1, cnt, 1, t, y, x, 1);
    } else {
      pair<int, int> g = now.first;
      int x = lower_bound(V.begin(), V.end(), g.first) - V.begin();
      int y = lower_bound(V.begin(), V.end(), g.second) - V.begin();
      int t = query(1, cnt, 1, y, 1);
      printf("%d\n", V[x] - V[t]);
      update(1, cnt, 1, y, y, x, 1);
      update(1, cnt, 1, t, x, y, 0);
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) solve();
  return 0;
}
