#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > up, ho;
set<pair<int, int> >::iterator it;
int main(void) {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    char op;
    cin >> y >> x >> op;
    if (op == 'U') {
      it = up.lower_bound(make_pair(y, -1));
      if (it == up.end()) {
        up.insert(make_pair(y, 0));
        ho.insert(make_pair(x, y));
        cout << x << endl;
        continue;
      }
      int yy = it->first, pos = it->second;
      if (yy == y) {
        cout << 0 << endl;
        continue;
      }
      up.insert(make_pair(y, pos));
      ho.insert(make_pair(x, y));
      cout << x - pos << endl;
    } else {
      it = ho.lower_bound(make_pair(x, -1));
      if (it == ho.end()) {
        ho.insert(make_pair(x, 0));
        up.insert(make_pair(y, x));
        cout << y << endl;
        continue;
      }
      int xx = it->first, pos = it->second;
      if (xx == x) {
        cout << 0 << endl;
        continue;
      }
      ho.insert(make_pair(x, pos));
      up.insert(make_pair(y, x));
      cout << y - pos << endl;
    }
  }
  return 0;
}
