#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
struct t {
  int v;
  t() { v = 0; }
  t(int v_) { v = v_; }
  t operator+(const t &t_) { return t(max(v, t_.v)); }
};
struct u {
  int v;
  u() { v = 0; }
  u(int v_) { v = v_; }
  t operator()(const t &t_) { return t(max(v, t_.v)); }
  u operator+(const u &u_) { return u(max(v, u_.v)); }
};
template <typename T, typename U>
struct seg_tree_lazy {
  int S, H;
  T zero;
  vector<T> value;
  U noop;
  vector<bool> dirty;
  vector<U> prop;
  seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()) {
    zero = _zero, noop = _noop;
    for (S = 1, H = 1; S < _S;) S *= 2, H++;
    value.resize(2 * S, zero);
    dirty.resize(2 * S, false);
    prop.resize(2 * S, noop);
  }
  void set_leaves(vector<T> &leaves) {
    copy(leaves.begin(), leaves.end(), value.begin() + S);
    for (int i = S - 1; i > 0; i--) value[i] = value[2 * i] + value[2 * i + 1];
  }
  void apply(int i, U &update) {
    value[i] = update(value[i]);
    if (i < S) {
      prop[i] = prop[i] + update;
      dirty[i] = true;
    }
  }
  void rebuild(int i) {
    for (int l = i / 2; l; l /= 2) {
      T combined = value[2 * l] + value[2 * l + 1];
      value[l] = prop[l](combined);
    }
  }
  void propagate(int i) {
    for (int h = H; h > 0; h--) {
      int l = i >> h;
      if (dirty[l]) {
        apply(2 * l, prop[l]);
        apply(2 * l + 1, prop[l]);
        prop[l] = noop;
        dirty[l] = false;
      }
    }
  }
  void upd(int i, int j, U update) {
    i += S, j += S;
    propagate(i), propagate(j);
    for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
      if ((l & 1) == 1) apply(l++, update);
      if ((r & 1) == 0) apply(r--, update);
    }
    rebuild(i), rebuild(j);
  }
  T query(int i, int j) {
    i += S, j += S;
    propagate(i), propagate(j);
    T res_left = zero, res_right = zero;
    for (; i <= j; i /= 2, j /= 2) {
      if ((i & 1) == 1) res_left = res_left + value[i++];
      if ((j & 1) == 0) res_right = value[j--] + res_right;
    }
    return res_left + res_right;
  }
};
int qu[200005][3];
int l[400005];
bool done[400005];
const int db = 0;
int main() {
  int n, q, a, b;
  char c;
  set<int> coords;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c;
    coords.insert(a);
    coords.insert(b);
    if (c == 'U') {
      qu[i][0] = 0;
      qu[i][1] = a;
      qu[i][2] = b;
    } else {
      qu[i][0] = 1;
      qu[i][1] = a;
      qu[i][2] = b;
    }
  }
  if (db) cout << "hi" << endl;
  map<int, int> m;
  int cur = 1;
  for (auto i : coords) {
    m[i] = cur;
    l[cur++] = i;
  }
  if (db) cout << "hi" << endl;
  seg_tree_lazy<t, u> foru(400005), forl(400005);
  if (db) cout << "hi" << endl;
  for (int qi = 0; qi < q; qi++) {
    if (db) cout << "Current query: " << qi << endl;
    if (done[m[qu[qi][1]]]) {
      cout << 0 << endl;
      continue;
    }
    done[m[qu[qi][1]]] = 1;
    if (qu[qi][0] == 0) {
      if (db) cout << "UP" << endl;
      int curcu = qu[qi][1];
      int curru = qu[qi][2];
      if (db) cout << "cur*u: " << curcu << " " << curru << endl;
      int curcc = m[curcu];
      int currc = m[curru];
      if (db) cout << "cur*c: " << curcc << " " << currc << endl;
      int minrc = foru.query(curcc, curcc).v;
      if (db) cout << "minrc: " << minrc << endl;
      int minru = l[minrc];
      if (db) cout << "minr*: " << minrc << " " << minru << endl;
      forl.upd(minrc, currc, u(curcc));
      cout << (curru - minru) << endl;
    } else {
      if (db) cout << "LEFT" << endl;
      int curcu = qu[qi][1];
      int curru = qu[qi][2];
      if (db) cout << "cur*u: " << curcu << " " << curru << endl;
      int curcc = m[curcu];
      int currc = m[curru];
      if (db) cout << "cur*c: " << curcc << " " << currc << endl;
      int mincc = forl.query(currc, currc).v;
      if (db) cout << "mincc: " << mincc << endl;
      int mincu = l[mincc];
      if (db) cout << "minc*: " << mincc << " " << mincu << endl;
      foru.upd(mincc, curcc, u(currc));
      cout << (curcu - mincu) << endl;
    }
  }
}
