#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<pair<pair<int, int>, char> > V;
int revR[800010];
map<int, int> R;
set<int> setR;
int tree[2000010][2];
int lazy[2000010][2];
void upd(int idx, int l, int r, int a, int b, int x, bool k) {
  if (idx * 2 + 1 < 2000010)
    lazy[idx * 2 + 1][k] = max(lazy[idx * 2 + 1][k], lazy[idx][k]);
  if (idx * 2 + 2 < 2000010)
    lazy[idx * 2 + 2][k] = max(lazy[idx * 2 + 2][k], lazy[idx][k]);
  tree[idx][k] = max(tree[idx][k], lazy[idx][k]);
  lazy[idx][k] = 0;
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    if (idx * 2 + 1 < 2000010)
      lazy[idx * 2 + 1][k] = max(lazy[idx * 2 + 1][k], x);
    if (idx * 2 + 2 < 2000010)
      lazy[idx * 2 + 2][k] = max(lazy[idx * 2 + 2][k], x);
    tree[idx][k] = max(tree[idx][k], x);
    return;
  }
  int mid = (l + r) / 2;
  upd(idx * 2 + 1, l, mid, a, b, x, k);
  upd(idx * 2 + 2, mid + 1, r, a, b, x, k);
  tree[idx][k] = max(tree[idx * 2 + 1][k], tree[idx * 2 + 2][k]);
}
int qu(int idx, int l, int r, int a, int b, int k) {
  if (idx * 2 + 1 < 2000010)
    lazy[idx * 2 + 1][k] = max(lazy[idx * 2 + 1][k], lazy[idx][k]);
  if (idx * 2 + 2 < 2000010)
    lazy[idx * 2 + 2][k] = max(lazy[idx * 2 + 2][k], lazy[idx][k]);
  tree[idx][k] = max(tree[idx][k], lazy[idx][k]);
  lazy[idx][k] = 0;
  if (l > b || r < a) return 0;
  if (l >= a && r <= b) {
    return tree[idx][k];
  }
  int mid = (l + r) / 2;
  return max(qu(idx * 2 + 1, l, mid, a, b, k),
             qu(idx * 2 + 2, mid + 1, r, a, b, k));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  int x, y;
  char c;
  for (int i = 0; i < q; i++) {
    cin >> x >> y >> c;
    V.push_back({{x, y}, c});
    setR.insert(x);
    setR.insert(y);
  }
  set<int>::iterator it;
  it = setR.begin();
  for (int i = 0;; i++) {
    if (setR.end() == it) break;
    R[*it] = i;
    revR[i] = *it;
    it++;
  }
  int tmpX, tmpY, m;
  for (int i = 0; i < q; i++) {
    x = V[i].first.first;
    y = V[i].first.second;
    c = V[i].second;
    if (c == 'U') {
      tmpX = R[x];
      tmpY = R[y];
      m = qu(0, 0, 400009, tmpX, tmpX, 0);
      upd(0, 0, 400009, R[m], tmpY, x, 1);
      upd(0, 0, 400009, tmpX, tmpX, y, 0);
      cout << y - m << "\n";
    } else {
      tmpX = R[x];
      tmpY = R[y];
      m = qu(0, 0, 400009, tmpY, tmpY, 1);
      upd(0, 0, 400009, R[m], tmpX, y, 0);
      upd(0, 0, 400009, tmpY, tmpY, x, 1);
      cout << x - m << "\n";
    }
  }
  return 0;
}
