#include <bits/stdc++.h>
using namespace std;
int n, q;
set<pair<int, pair<int, int> > > s;
set<pair<int, pair<int, int> > >::iterator t;
map<int, bool> c, r;
string S;
int main() {
  cin >> n >> q;
  s.insert(make_pair(0, make_pair(0, 1)));
  s.insert(make_pair(n + 1, make_pair(0, 0)));
  for (int x, y, ans, k, a, b; q--;) {
    cin >> x >> y >> S;
    if (c[y] || r[x]) {
      cout << 0 << endl;
      continue;
    }
    t = s.upper_bound(make_pair(x, make_pair(0, 0)));
    if (S == "L") t--;
    k = (*t).second.second;
    a = (*t).second.first;
    b = (*t).first;
    if (S == "U") {
      if (k == 0)
        ans = b - x;
      else
        ans = a + b - x;
    } else {
      if (k == 0)
        ans = x - b + a;
      else
        ans = x - b;
    }
    cout << ans << endl;
    s.insert(make_pair(x, make_pair(ans, (int)(S == "U"))));
    c[y] = true;
    r[x] = true;
  }
}
