#include <bits/stdc++.h>
using namespace std;
int n, q;
map<int, int> up, lef;
void update_up(int x, int y) {
  int ans = n;
  auto it = up.lower_bound(x);
  if (it->first == x) {
    printf("0\n");
    return;
  }
  int reach = (n + 1 - it->second) - it->first + 1;
  ans = min(ans, y - reach + 1);
  auto it2 = lef.lower_bound(x);
  if (it2->first == x) {
    printf("0\n");
    return;
  } else if (it2->first < it->first && it2->first > x) {
    ans = min(ans, y - (n + 1 - it2->first));
  }
  printf("%d\n", ans);
  up[x] = ans;
}
void update_lef(int x, int y) {
  int ans = n;
  auto it = lef.upper_bound(x);
  it--;
  if (it->first == x) {
    printf("0\n");
    return;
  }
  int reach = it->first - it->second + 1;
  ans = min(ans, x - reach + 1);
  auto it2 = up.upper_bound(x);
  it2--;
  if (it2->first == x) {
    printf("0\n");
    return;
  } else if (it2->first > it->first && it2->first < x) {
    reach = x - it2->first;
    ans = min(ans, reach);
  }
  printf("%d\n", ans);
  lef[x] = ans;
}
int main(void) {
  scanf("%d %d", &n, &q);
  up[0] = n + 1;
  up[n + 1] = 0;
  lef[0] = 0;
  lef[n + 1] = n + 1;
  for (int i = 0; i < q; i++) {
    int x, y;
    char c;
    scanf("%d %d %c", &x, &y, &c);
    if (c == 'U') {
      update_up(x, y);
    } else {
      update_lef(x, y);
    }
  }
  return 0;
}
