#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
	int li;
	int ri;
	Node *l;
	Node *r;

	int val;

	bool hupd;
	int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
	Node *n = new Node;
	n->li = li;
	n->ri = ri;
	n->upd = 0;
	if(li == ri){
		n->val = -1; //init
	}else{
		int mi = (li+ri)/2;
		n->l = build(li, mi);
		n->r = build(mi+1, ri);

		n->val = std::max(n->l->val, n->r->val); // merge
	}
	return n;
}

int query(Node *n, int li, int ri){
	if(ri < n->li || n->ri < li){
		//outside
		return -1;
	}else if(li <= n->li && n->ri <= ri){
		//inside
		return n->val;
	}

	int la = query(n->l, li, ri);
	int ra = query(n->r, li, ri);
	return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
	if(ri < n->li || n->ri < li){
		//outside
		return;
	}else if(li <= n->li && n->ri <= ri){
		n->val = v; //update
		return;
	}

	update(n->l, li, ri, v);
	update(n->r, li, ri, v);
	n->val = std::max(n->r->val, n->l->val); // merge
}

int bquery(Node *n, int li, int ri, int mi){
	if(ri < n->li || n->ri < li){
		//outside
		return INT_MAX;
	}else if(li <= n->li && n->ri <= ri){
		//inside
		if(n->li == n->ri){
			if(n->val < mi) return n->li;
			return INT_MAX;
		}else if(n->r->val < mi) return std::min(n->r->li, bquery(n->l, li, ri, mi));
		else return bquery(n->r, li, ri, mi);
	}

	int a = query(n->r, li, ri);
	if(a < mi) return std::min(n->r->li, bquery(n->l, li, ri, mi));
	else return bquery(n->r, li, ri, mi);
}

int main(){
	std::cin >> n >> q;
	r = build(0, 211111);
	r2 = build(0, 211111);

	std::set<int> tx;
	std::set<int> ty;
	std::set<std::pair<int, int >> hs;
	for(int i=0; i<q; ++i){
		std::cin >> nx[i] >> ny[i] >> nc[i];
		tx.insert(nx[i]);
		ty.insert(ny[i]);
	}
	int c = 1;
	for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
		mpx[*iter] = c;
		mpxr[c] = *iter;
		++c;
	}
	int cxl = c;
	c = 1;
	for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
		mpy[*iter] = c;
		mpyr[c] = *iter;
		++c;
	}
	int cyl = c;
	for(int i=0; i<q; ++i){
		if(hs.find(std::make_pair(nx[i], ny[i])) != hs.end()) {
			std::cout << 0 << std::endl;
			continue;
		}
		hs.insert(std::make_pair(nx[i], ny[i]));
		if(nc[i] == 'L'){
			int mn = bquery(r, 0, mpx[nx[i]], cyl-mpy[ny[i]]);
			if(mn == 0){
				std::cout << nx[i] << std::endl;
			}else{
				std::cout << nx[i]-mpxr[mn-1] << std::endl;
			}
			update(r2, mpy[ny[i]], mpy[ny[i]], cxl-mn);

			//return 0;
		}else{
			int mn = bquery(r2, 0, mpy[ny[i]], cxl-mpx[nx[i]]);
			if(mn == 0){
				std::cout << ny[i] << std::endl;
			}else{
				std::cout << ny[i]-mpyr[mn-1] << std::endl;
			}
			update(r, mpx[nx[i]], mpx[nx[i]], cyl-mn);
		}
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using std::sort;
using std::lower_bound;

const int N = 2e5 + 10;

inline void Maxed(int& h, int g) {
  if (h < g)
    h = g;
}

int n, m;

struct Q {
  int x, y; char op;
}q[N];
int sx[N], sy[N];

struct Seg {
  int back[N * 4];
  inline int lson(int k) { return k * 2; }
  inline int rson(int k) { return k * 2 + 1; }
  void pushdown(int k) {
    Maxed(back[lson(k)], back[k]);
    Maxed(back[rson(k)], back[k]);
  }
  void modify(int k, int l, int r, int x, int y, int v) {
    if (y < l or r < x)
      return;
    if (x <= l and r <= y) {
      Maxed(back[k], v);
      return;
    }
    pushdown(k);
    int mid = (l + r) / 2;
    modify(lson(k), l, mid, x, y, v);
    modify(rson(k), mid + 1, r, x, y, v);
  }
  int query(int k, int l, int r, int x) {
    if (l == r)
      return back[k];
    pushdown(k);
    int mid = (l + r) / 2;
    if (x <= mid)
      return query(lson(k), l, mid, x);
    return query(rson(k), mid + 1, r, x);
  }
}up, left;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %c", &q[i].x, &q[i].y, &q[i].op);
    sx[i] = q[i].x, sy[i] = q[i].y;
  }
  sort(sx + 1, sx + m + 1);
  sort(sy + 1, sy + m + 1);
  for (int i = 1; i <= m; ++i) {
    q[i].x = lower_bound(sx + 1, sx + m + 1, q[i].x) - sx;
    q[i].y = lower_bound(sy + 1, sy + m + 1, q[i].y) - sy;
  }

  for (int i = 1; i <= m; ++i) {
    int x = q[i].x, y = q[i].y; char op = q[i].op;
    if (op == 'L') {
      int back_x = left.query(1, 1, m, y);
      printf("%d\n", sx[x] - sx[back_x]);
      up.modify(1, 1, m, back_x + 1, x, y);
    }
    else { // 'U'
      int back_y = up.query(1, 1, m, x);
      printf("%d\n", sy[y] - sy[back_y]);
      left.modify(1, 1, m, back_y + 1, y, x);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstring>

const int N = 2e5 + 10;

inline void Maxed(int& h, int g) {
  if (h < g)
    h = g;
}

int n, q;

struct Seg {
  int back[N * 4];
  inline int lson(int k) { return k * 2; }
  inline int rson(int k) { return k * 2 + 1; }
  void pushdown(int k) {
    Maxed(back[lson(k)], back[k]);
    Maxed(back[rson(k)], back[k]);
  }
  void modify(int k, int l, int r, int x, int y, int v) {
    if (y < l or r < x)
      return;
    if (x <= l and r <= y) {
      Maxed(back[k], v);
      return;
    }
    pushdown(k);
    int mid = (l + r) / 2;
    modify(lson(k), l, mid, x, y, v);
    modify(rson(k), mid + 1, r, x, y, v);
  }
  int query(int k, int l, int r, int x) {
    if (l == r)
      return back[k];
    pushdown(k);
    int mid = (l + r) / 2;
    if (x <= mid)
      return query(lson(k), l, mid, x);
    return query(rson(k), mid + 1, r, x);
  }
}up, left;

int main() {
  scanf("%d %d", &n, &q);
  while (q--) {
    int x, y; char op;
    scanf("%d %d %c", &x, &y, &op);
    if (op == 'L') {
      int back_x = left.query(1, 1, n, y);
      printf("%d\n", x - back_x);
      up.modify(1, 1, n, back_x + 1, x, y);
    }
    else { // 'U'
      int back_y = up.query(1, 1, n, x);
      printf("%d\n", y - back_y);
      left.modify(1, 1, n, back_y + 1, y, x);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using std::sort;
using std::lower_bound;

const int N = 2e5 + 10;

inline void Maxed(int& h, int g) {
  if (h < g)
    h = g;
}

int n, m;

struct Q {
  int x, y; char op;
}q[N];
int sx[N], sy[N];

struct Seg {
  int back[N * 4];
  inline int lson(int k) { return k * 2; }
  inline int rson(int k) { return k * 2 + 1; }
  void pushdown(int k) {
    Maxed(back[lson(k)], back[k]);
    Maxed(back[rson(k)], back[k]);
  }
  void modify(int k, int l, int r, int x, int y, int v) {
    if (y < l or r < x)
      return;
    if (x <= l and r <= y) {
      Maxed(back[k], v);
      return;
    }
    pushdown(k);
    int mid = (l + r) / 2;
    modify(lson(k), l, mid, x, y, v);
    modify(rson(k), mid + 1, r, x, y, v);
  }
  int query(int k, int l, int r, int x) {
    if (l == r)
      return back[k];
    pushdown(k);
    int mid = (l + r) / 2;
    if (x <= mid)
      return query(lson(k), l, mid, x);
    return query(rson(k), mid + 1, r, x);
  }
}up, left;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %c", &q[i].x, &q[i].y, &q[i].op);
    sx[i] = q[i].x, sy[i] = q[i].y;
  }
  sort(sx + 1, sx + m + 1);
  sort(sy + 1, sy + m + 1);
  for (int i = 1; i <= m; ++i) {
    q[i].x = lower_bound(sx + 1, sx + m + 1, q[i].x) - sx;
    q[i].y = lower_bound(sy + 1, sy + m + 1, q[i].y) - sy;
  }

  for (int i = 1; i <= m; ++i) {
    int x = q[i].x, y = q[i].y; char op = q[i].op;
    if (op == 'L') {
      int back_x = left.query(1, 1, m, y);
      printf("%d\n", sx[x] - sx[back_x]);
      up.modify(1, 1, m, back_x + 1, x, y);
      left.modify(1, 1, m, y, y, x);
    }
    else { // 'U'
      int back_y = up.query(1, 1, m, x);
      printf("%d\n", sy[y] - sy[back_y]);
      left.modify(1, 1, m, back_y + 1, y, x);
      up.modify(1, 1, m, x, x, y);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using std::sort;
using std::lower_bound;

const int N = 2e5 + 10;

inline void Maxed(int& h, int g) {
  if (h < g)
    h = g;
}

int n, m;

struct Q {
  int x, y; char op;
}q[N];
int sx[N], sy[N];

struct Seg {
  int back[N * 4];
  inline int lson(int k) { return k * 2; }
  inline int rson(int k) { return k * 2 + 1; }
  void pushdown(int k) {
    Maxed(back[lson(k)], back[k]);
    Maxed(back[rson(k)], back[k]);
  }
  void modify(int k, int l, int r, int x, int y, int v) {
    if (y < l or r < x)
      return;
    if (x <= l and r <= y) {
      Maxed(back[k], v);
      return;
    }
    pushdown(k);
    int mid = (l + r) / 2;
    modify(lson(k), l, mid, x, y, v);
    modify(rson(k), mid + 1, r, x, y, v);
  }
  int query(int k, int l, int r, int x) {
    if (l == r)
      return back[k];
    pushdown(k);
    int mid = (l + r) / 2;
    if (x <= mid)
      return query(lson(k), l, mid, x);
    return query(rson(k), mid + 1, r, x);
  }
}up, left;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %c", &q[i].x, &q[i].y, &q[i].op);
    sx[i] = q[i].x, sy[i] = q[i].y;
  }
  sort(sx + 1, sx + m + 1);
  sort(sy + 1, sy + m + 1);
  for (int i = 1; i <= m; ++i) {
    q[i].x = lower_bound(sx + 1, sx + m + 1, q[i].x) - sx;
    q[i].y = lower_bound(sy + 1, sy + m + 1, q[i].y) - sy;
  }

  for (int i = 1; i <= m; ++i) {
    int x = q[i].x, y = q[i].y; char op = q[i].op;
    if (op == 'L') {
      int back_x = left.query(1, 1, n, y);
      printf("%d\n", sx[x] - sx[back_x]);
      up.modify(1, 1, n, back_x + 1, x, y);
    }
    else { // 'U'
      int back_y = up.query(1, 1, n, x);
      printf("%d\n", sy[y] - sy[back_y]);
      left.modify(1, 1, n, back_y + 1, y, x);
    }
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using std::sort;
using std::lower_bound;

const int N = 2e5 + 10;

inline void Maxed(int& h, int g) {
  if (h < g)
    h = g;
}

int opopopo() {return 0;}

int n, m;

struct Q {
  int x, y; char op;
}q[N];
int sx[N], sy[N];

struct Seg {
  int back[N * 4];
  inline int lson(int k) { return k * 2; }
  inline int rson(int k) { return k * 2 + 1; }
  void pushdown(int k) {
    Maxed(back[lson(k)], back[k]);
    Maxed(back[rson(k)], back[k]);
  }
  void modify(int k, int l, int r, int x, int y, int v) {
    if (y < l or r < x)
      return;
    if (x <= l and r <= y) {
      Maxed(back[k], v);
      return;
    }
    pushdown(k);
    int mid = (l + r) / 2;
    modify(lson(k), l, mid, x, y, v);
    modify(rson(k), mid + 1, r, x, y, v);
  }
  int query(int k, int l, int r, int x) {
    if (l == r)
      return back[k];
    pushdown(k);
    int mid = (l + r) / 2;
    if (x <= mid)
      return query(lson(k), l, mid, x);
    return query(rson(k), mid + 1, r, x);
  }
}up, left;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %c", &q[i].x, &q[i].y, &q[i].op);
    sx[i] = q[i].x, sy[i] = q[i].y;
  }
  sort(sx + 1, sx + m + 1);
  sort(sy + 1, sy + m + 1);
  for (int i = 1; i <= m; ++i) {
    q[i].x = lower_bound(sx + 1, sx + m + 1, q[i].x) - sx;
    q[i].y = lower_bound(sy + 1, sy + m + 1, q[i].y) - sy;
  }

  for (int i = 1; i <= m; ++i) {
    int x = q[i].x, y = q[i].y; char op = q[i].op;
    if (op == 'L') {
      int back_x = left.query(1, 1, m, y);
      printf("%d\n", sx[x] - sx[back_x]);
      up.modify(1, 1, m, back_x + 1, x, y);
      left.modify(1, 1, m, y, y, x);
    }
    else { // 'U'
      int back_y = up.query(1, 1, m, x);
      printf("%d\n", sy[y] - sy[back_y]);
      left.modify(1, 1, m, back_y + 1, y, x);
      up.modify(1, 1, m, x, x, y);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std ;
int x[200200],y[200200];
map<int,int> mp;

int main(){
    int n,q;
    cin >> n >> q ;
    mp[0]=mp[n+1]=q;
    for(int i=q-1;i>=0;i--){
        char c ;
        cin >> x[i] >> y[i] >> c ;
        if(c=='U'){
            map<int,int>::iterator it;
            it=mp.lower_bound(x[i]);
            mp[x[i]]=i;
            if(it->first==x[i]){
                cout << '0' << endl ;
                continue;
            }
            else{
                int ans ;
                ans=y[i]-y[it->second];
                cout << ans << endl ;
                y[i]=y[it->second];
            }
        }else{
            map<int,int>::iterator it;
            it=mp.lower_bound(x[i]);
            mp[x[i]]=i;
            if(it->first==x[i]){
                cout << '0' << endl ;
                continue;
            }
            else{
                it--;it--;
                int ans ;
                ans=x[i]-x[it->second];
                cout << ans << endl ;
                x[i]=x[it->second];
            }

        }
    }
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;char c;}a[200000+5];
struct node1{long long now,id;}b[200000+5];
long long Q1[200000+5],Q2[200000+5],ans[200000+5];
bool cmp(node1 A,node1 B)
{
	return A.now<B.now;
}
int main()
{
	long long n,q,i,head1=0,head2=0;
	cin >> n >> q;
	for (i=1;i<=q;i++)
	{
		cin >> a[i].x >> a[i].y >> a[i].c;
		b[i].now=a[i].x;
		b[i].id=i;
	}
	sort(b+1,b+q+1,cmp);
	for (i=1;i<=q;i++)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='U'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='U')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].x-a[Q2[head2]].x;
			}
			else
				ans[b[i].id]=a[b[i].id].x;
		}
	}
	head1=head2=0;
	for (i=q;i>=1;i--)
	{
		while(head1>0&&Q1[head1]>b[i].id)
		{
			int j=Q1[head1];
			if (a[j].c=='L'&&head2>0)
			{
				head2--;
			}
			head1--;
		}
		Q1[++head1]=b[i].id;
		if (a[b[i].id].c=='L')
			Q2[++head2]=b[i].id;
		else
		{
			if (head2>0)
			{
				ans[b[i].id]=a[b[i].id].y-a[Q2[head2]].y;
			}
			else
				ans[b[i].id]=a[b[i].id].y;
		}
	}
	for (i=1;i<=q;i++)
		cout << ans[i] <<endl;
}


#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
char s[2];
const int maxn=1e7;
int root1,root2,cnt,ls[maxn],rs[maxn],ma[maxn],lazy[maxn],ask[maxn];
int n,m;
void distri(int i){
    if(!ls[i]) ls[i]=++cnt;
    if(!rs[i]) rs[i]=++cnt;
    ma[ls[i]]=max(lazy[i],ma[ls[i]]);
    ma[rs[i]]=max(lazy[i],ma[rs[i]]);
    lazy[ls[i]]=lazy[rs[i]]=lazy[i];
    lazy[i]=0;
}
int query(int &i,int l,int r,int x){
    if(!i) i=++cnt;
    if(l==r){
    	if(!ask[i]){
		    ask[i]=1;
		    return ma[i];
		}else{
		    return n+1-x;
		}
	}
    if(lazy[i]) distri(i);
    int mid=l+r>>1;
    //printf("*");
    if(x<=mid) return query(ls[i],l,mid,x);
    else return query(rs[i],mid+1,r,x);
}
void modify(int &i,int l,int r,int x,int y,int ah){
	if(x>y||l>y||r<x) return;
    if(!i) i=++cnt;
    if(l>=x&&r<=y){
	    ma[i]=max(ma[i],ah);
	    lazy[i]=ah;
	    return;
	}
	//printf("%d %d %d\n",i,l,r);
	if(lazy[i]) distri(i);
	int mid=l+r>>1;
	if(x<=mid) modify(ls[i],l,mid,x,y,ah);
	if(mid<y) modify(rs[i],mid+1,r,x,y,ah);
	ma[i]=max(ma[ls[i]],ma[rs[i]]);
}
int main() {
	int x,y;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; i++) {
		scanf("%d%d%s",&x,&y,s);
		if(s[0]=='U'){
		    int big=query(root1,1,n,x);
		    printf("%d\n",y-big);
		    modify(root2,1,n,big+1,y,x);
		}else{
		    int big=query(root2,1,n,y);
		    printf("%d\n",x-big);
		    modify(root1,1,n,big+1,x,y);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
int n, m;
set<int> X, Y;

int main() {
	int x, y; char opt;
	scanf("%d%d", &n, &m), X.insert(0), Y.insert(0);
	for(; m; --m) {
		scanf("%d%d", &y, &x);
		for(opt = getchar(); opt != 'U' && opt != 'L'; opt = getchar());
		if(opt == 'U') {
			set<int>::iterator it = --Y.upper_bound(x);
			printf("%d\n", x - *it), X.insert(y);
		}
		else {
			set<int>::iterator it = --X.upper_bound(y);
			printf("%d\n", y - *it), Y.insert(x);
		}
	}
	return 0;
}


// =================================
//   author: memset0
//   date: 2019.04.06 11:29:18
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define debug(...) ((void)0)
#ifndef debug
#define debug(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace ringo {
template <class T> inline void read(T &x) {
	x = 0; register char c = getchar(); register bool f = 0;
	while (!isdigit(c)) f ^= c == '-', c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
	if (f) x = -x;
}
template <class T> inline void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }

const int N = 2e5 + 10;
int n, m;

struct seg {
	static const int M = N * 30;
	int rt, cnt, lim[M], lc[M], rc[M];
	void modify(int &u, int ql, int qr, int v, int l, int r) {
		if (!u) u = ++cnt;
		// printf(">> modify %d %d %d %d %d %d\n", u, ql, qr, v, l, r);
		if (ql == l && qr == r) { lim[u] = std::max(lim[u], v); return; }
		int mid = (l + r) >> 1;
		if (qr <= mid) modify(lc[u], ql, qr, v, l, mid);
		else if (ql > mid) modify(rc[u], ql, qr, v, mid + 1, r);
		else modify(lc[u], ql, mid, v, l, mid), modify(rc[u], mid + 1, qr, v, mid + 1, r);
	}
	int query(int u, int ql, int qr, int l, int r) {
		if (!u) return 0;
		if (ql == l && qr == r) return lim[u];
		int mid = (l + r) >> 1;
		if (qr <= mid) return std::max(lim[u], query(lc[u], ql, qr, l, mid));
		if (ql > mid) return std::max(lim[u], query(rc[u], ql, qr, mid + 1, r));
		return std::max(lim[u], std::max(query(lc[u], ql, mid, l, mid), query(rc[u], mid + 1, qr, mid + 1, r)));
	}
	inline int query(int k) { return query(rt, k, k, 1, n); }
	inline void modify(int k, int v) { modify(rt, k, k, v, 1, n); }
	inline int query(int l, int r) { return query(rt, l, r, 1, n); }
	inline void modify(int l, int r, int v) { modify(rt, l, r, v, 1, n); }
} l, u;

int main() {
	read(n), read(m);
	for (int i = 1, x, y, opt, limit; i <= m; i++) {
		read(x), read(y), opt = getchar();
		// printf(">>> %d %d %c\n", x, y, opt);
		if (opt == 'U') {
			limit = u.query(x);
			u.modify(x, y);
			l.modify(x, n - limit, x);
			print(y - limit, '\n');
		} else if (opt == 'L') {
			limit = l.query(x);
			l.modify(x, y);
			u.modify(limit + 1, x, y);
			print(x - limit, '\n');
		}
	}
}

} signed main() {
#ifdef MEMSET0_LOCAL_ENVIRONMENT
	freopen("1.in", "r", stdin);
#endif
	return ringo::main(), 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=5000005;
int mx[N],son[2][N],tot;
map<pair<int,int>,int>mp;
struct seg
{
	int rt;
	void pushdown(int x)
	{
		if(!son[0][x]) son[0][x]=++tot;
		if(!son[1][x]) son[1][x]=++tot;
		mx[son[0][x]]=max(mx[son[0][x]],mx[x]);
		mx[son[1][x]]=max(mx[son[1][x]],mx[x]);
	}
	void add(int L,int R,int z,int l,int r,int &x)
	{
		if(!x) x=++tot;
		if(l>=L&&r<=R){mx[x]=max(mx[x],z);return;}
		pushdown(x);
		int mid=(l+r)>>1;
		if(mid>=L) add(L,R,z,l,mid,son[0][x]);
		if(mid<R) add(L,R,z,mid+1,r,son[1][x]);
	}
	int que(int y,int l,int r,int x)
	{
		if(!x) return 0;
		if(l==r) return mx[x];
		pushdown(x);
		int mid=(l+r)>>1;
		if(y<=mid) return que(y,l,mid,son[0][x]);
		else return que(y,mid+1,r,son[1][x]);
	}
} t1,t2;
char s[55];
int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	while(q--)
	{
		int x,y;
		scanf("%d%d%s",&x,&y,s);
		if(mp[make_pair(x,y)]){printf("0\n");continue;}
		mp[make_pair(x,y)]=1;
		if(s[0]=='U')
		{
			int v=y-t1.que(x,1,n,t1.rt);
			printf("%d\n",v);
			t2.add(y-v+1,y,x,1,n,t2.rt);
		}
		else
		{
			int v=x-t2.que(y,1,n,t2.rt);
			printf("%d\n",v);
			t1.add(x-v+1,x,y,1,n,t1.rt);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=20000005;
int mx[N],son[2][N],tot;
map<pair<int,int>,int>mp;
struct seg
{
	int rt;
	void pushdown(int x)
	{
		if(!son[0][x]) son[0][x]=++tot;
		if(!son[1][x]) son[1][x]=++tot;
		mx[son[0][x]]=max(mx[son[0][x]],mx[x]);
		mx[son[1][x]]=max(mx[son[1][x]],mx[x]);
	}
	void add(int L,int R,int z,int l,int r,int &x)
	{
		if(!x) x=++tot;
		if(l>=L&&r<=R){mx[x]=max(mx[x],z);return;}
		pushdown(x);
		int mid=(l+r)>>1;
		if(mid>=L) add(L,R,z,l,mid,son[0][x]);
		if(mid<R) add(L,R,z,mid+1,r,son[1][x]);
	}
	int que(int y,int l,int r,int x)
	{
		if(!x) return 0;
		if(l==r) return mx[x];
		pushdown(x);
		int mid=(l+r)>>1;
		if(y<=mid) return que(y,l,mid,son[0][x]);
		else return que(y,mid+1,r,son[1][x]);
	}
} t1,t2;
char s[55];
int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	while(q--)
	{
		int x,y;
		scanf("%d%d%s",&x,&y,s);
		if(mp[make_pair(x,y)]){printf("0\n");continue;}
		mp[make_pair(x,y)]=1;
		if(s[0]=='U')
		{
			int v=y-t1.que(x,1,n,t1.rt);
			printf("%d\n",v);
			t2.add(y-v+1,y,x,1,n,t2.rt);
		}
		else
		{
			int v=x-t2.que(y,1,n,t2.rt);
			printf("%d\n",v);
			t1.add(x-v+1,x,y,1,n,t1.rt);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>

using namespace std;

int n, m, ans;

class Squares
{
public:
    int l, r;
    int len_l, len_u;
    Squares()
    {
        l = r = 0;
        len_l = len_u = 0;
    }
    Squares(int _l, int _r, int _len_l, int _len_u)
    {
        l = _l, r = _r;
        len_l = _len_l, len_u = _len_u;
    }
    bool operator < (const Squares &b)const
    {
        return r < b.r;
    }
} a, res, nxt;

set<Squares> s;
set<Squares>::iterator it;

inline int read()
{
    char ch = getchar();
    int ret = 0, f = 1;
    while (ch > '9' || ch < '0')
    {
        if (ch == '-')
            f = -f;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        ret = ret * 10 + ch - '0', ch = getchar();
    return ret * f;
}

int main()
{
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    n = read(), m = read();
    res = Squares(1, n, 0, 0);
    s.insert(res);
    while (m--)
    {
        int x = read(), y = read();
        char ch = getchar();
        while (ch != 'U' && ch != 'L')
            ch = getchar();
        a = Squares(x, x, 0, 0);
        it = s.lower_bound(a);
        if (it == s.end() || it->l > x || it->r < x)
        {
            // printf("Runtime Error !\n");
            // break;
            printf("0\n");
            continue;
        }
        res = *it;
        s.erase(it);
        if (ch == 'U')
        {
            ans = res.r - x + 1 + res.len_u;
            printf("%d\n", ans);
            if (x != res.l)
            {
                nxt = Squares(res.l, x - 1, res.len_l, ans);
                s.insert(nxt);
            }
            if (x != res.r)
            {
                nxt = Squares(x + 1, res.r, 0, res.len_u);
                s.insert(nxt);
            }
        }
        else
        {
            ans = x - res.l + 1 + res.len_l;
            printf("%d\n", ans);
            if (x != res.l)
            {
                nxt = Squares(res.l, x - 1, res.len_l, 0);
                s.insert(nxt);
            }
            if (x != res.r)
            {
                nxt = Squares(x + 1, res.r, ans, res.len_u);
                s.insert(nxt);
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
#include <utility>
#include <cmath>
using namespace std;

map<int, pair<char, int> > mp;
map<int, pair<char, int> >::iterator it;

int eat(){
	int x, y;
	char c;
	cin >> x >> y >> c;
	it = mp.lower_bound(x);
	if(it->first == x)return 0;
	if(c == 'L') it--;
	int ans = abs(it->first - x);
	if(it->second.first == c)
		ans += it->second.second;
	mp[x] = make_pair(c, ans);
	return ans;
}
int main(){
	int n, q;
	scanf("%d%d", &n, &q);
	int i;
	mp[0] = make_pair('L', 0);
	mp[n + 1] = make_pair('U', 0);
	for(i = 1; i <= q; i++){
		printf("%d\n", eat());
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 5, lg = 62;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, x);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, y);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 5, lg = 31;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == 0)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == 0)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, x);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, y);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 5, lg = 128;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, x);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, y);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 20, lg = 31;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, id * 2, l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, id * 2 + 1, mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, id * 2, l, mid);
	split(b, ll, rr, st, x, y, k, id * 2 + 1, mid, r);
}

int main()
{
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, x);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, y);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 20, lg = 248;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, x);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, y);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 5, lg = 31;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == -1)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, x);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, y);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 5, lg = 31;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == 0)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == 0)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, y);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, x);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e9 + 5, inf = 1e9 + 7, maxx = 2e5 + 5, lg = 61;

int stu[lg * maxx + 10], stl[lg * maxx + 10];
int rr_u[lg * maxx + 10], ll_l[lg * maxx + 10];
int rr_l[lg * maxx + 10], ll_u[lg * maxx + 10];
int c, x, y, l, r, t, n, q, cntl = 2, cntu = 2;

void extend_l(int v, int *ll, int *rr)
{
	if (ll[v] == 0)
		ll[v] = cntl++, rr[v] = cntl++;
}

void extend_u(int v, int *ll, int *rr)
{
	if (ll[v] == 0)
		ll[v] = cntu++, rr[v] = cntu++;
}

int get(int b, int *ll, int *rr, int *st, int x, int id = 1, int l = 0, int r = n)
{
	if (l + 1 == r)
		return st[id];
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	if (x < mid)
		return max(st[id], get(b, ll, rr, st, x, ll[id], l, mid));
	else
		return max(st[id], get(b, ll, rr, st, x, rr[id], mid, r));
}

void split(int b, int *ll, int *rr, int *st, int x, int y, int k, int id = 1, int l = 0, int r = n)
{
	if (x >= r || l >= y)
		return;
	if (x <= l && r <= y)
	{
		st[id] = max(st[id], k);
		return;
	}
	if (b)
		extend_l(id, ll, rr);
	else
		extend_u(id, ll, rr);
	int mid = (l + r) / 2;
	split(b, ll, rr, st, x, y, k, ll[id], l, mid);
	split(b, ll, rr, st, x, y, k, rr[id], mid, r);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	n++;
	split(1, ll_l, rr_l, stl, 0, n, 0);
	split(0, ll_u, rr_u, stu, 0, n, 0);
	for(int i = 0; i < q; i++)
	{
		char c;
		cin >> x >> y >> c;
		if (c == 'U')
		{
			int e = get(1, ll_l, rr_l, stl, x);
//			cout << e << " " << y - e << endl;
			cout << y - e << "\n";
			split(1, ll_l, rr_l, stl, x, x + 1, y);
			split(0, ll_u, rr_u, stu, e + 1, y + 1, x);
		}
		else
		{
			int e = get(0, ll_u, rr_u, stu, y);
//			cout << e << " " << x - e << endl;
			cout << x - e << "\n";
			split(0, ll_u, rr_u, stu, y, y + 1, x);
			split(1, ll_l, rr_l, stl, e + 1, x + 1, y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n, q;

struct query {
    int x, y;
    char a;
};
query tab[200005];
map <int,int> mapa;

const int p = 21;
int tree[1 << p][2];
int M = 1 << (p - 1);

void insert(int left, int right, int val, int id) {
    left += M;
    right += M;
    tree[left][id] = max(tree[left][id], val);
    tree[right][id] = max(tree[right][id], val);
    while(left / 2 != right / 2) {
        if(left % 2 == 0) tree[left + 1][id] = max(tree[left + 1][id], val);
        if(right % 2 == 1) tree[right - 1][id] = max(tree[right - 1][id], val);
        left /= 2; right /= 2;
    }
}

int query(int pos, int id) {
    pos += M;
    int ans = tree[pos][id];
    while(pos) {
        ans = max(ans, tree[pos][id]);
        pos /= 2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    scanf("%d %d", &n, &q);

    for(int i = 0; i < q; i++) {
        scanf("%d %d %c",&tab[i].x, &tab[i].y, &tab[i].a);
        mapa[tab[i].x] = mapa[tab[i].y] = 1;
    }
    mapa[n] = 1;
    int idx = 1;
    for(map <int,int> :: iterator it = mapa.begin(); it != mapa.end(); it++) {
        mapa[(*it).first] = idx++;
    }

    for(int i = 1; i < (1 << p); i++)
        tree[i][0] = tree[i][1] = 0;

    for(int i = 0; i < q; i++) {

        if(tab[i].a == 'U') {
            int tmp = tab[i].y - query(tab[i].x, 0);
//          cerr << query(tab[i].x, 0) << "!" << endl;
            printf("%d\n", tmp);
            insert(mapa[tab[i].y - tmp + 1], mapa[tab[i].y], tab[i].x, 1);
//          cerr << "Insert po y " << tab[i].y - tmp + 1 << " " << tab[i].y << " <- " << tab[i].x << endl;
        } else {
            int tmp = tab[i].x - query(tab[i].y, 1);
//          cerr << query(tab[i].y, 1) << "!!" << endl;
            printf("%d\n",tmp);
            insert(mapa[tab[i].x - tmp + 1], mapa[tab[i].x], tab[i].y, 0);
//          cerr << "Insert po x " << tab[i].x - tmp + 1 << " " << tab[i].x << " <- " << tab[i].y << endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;

int n, q;

struct query {
    int x, y;
    char a;
};
query tab[200005];
map <int,int> mapa;

const int p = 21;
int tree[1 << p][2];
int M = 1 << (p - 1);

void insert(int left, int right, int val, int id) {
    left += M;
    right += M;
    tree[left][id] = max(tree[left][id], val);
    tree[right][id] = max(tree[right][id], val);
    while(left / 2 != right / 2) {
        if(left % 2 == 0) tree[left + 1][id] = max(tree[left + 1][id], val);
        if(right % 2 == 1) tree[right - 1][id] = max(tree[right - 1][id], val);
        left /= 2; right /= 2;
    }
}

int query(int pos, int id) {
    pos += M;
    int ans = tree[pos][id];
    while(pos) {
        ans = max(ans, tree[pos][id]);
        pos /= 2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    scanf("%d %d", &n, &q);

    for(int i = 0; i < q; i++) {
        scanf("%d %d %c",&tab[i].x, &tab[i].y, &tab[i].a);
        mapa[tab[i].x] = mapa[tab[i].y] = 1;
    }
    mapa[n] = 1;
    int idx = 1;
    for(map <int,int> :: iterator it = mapa.begin(); it != mapa.end(); it++) {
        mapa[(*it).first] = idx++;
    }

    for(int i = 1; i < (1 << p); i++)
        tree[i][0] = tree[i][1] = 0;

    for(int i = 0; i < q; i++) {

        if(tab[i].a == 'U') {
            int tmp = tab[i].y - query(mapa[tab[i].x], 0);
//          cerr << query(tab[i].x, 0) << "!" << endl;
            printf("%d\n", tmp);
            insert(mapa[tab[i].y - tmp + 1], mapa[tab[i].y], tab[i].x, 1);
//          cerr << "Insert po y " << tab[i].y - tmp + 1 << " " << tab[i].y << " <- " << tab[i].x << endl;
        } else {
            int tmp = tab[i].x - query(mapa[tab[i].y], 1);
//          cerr << query(tab[i].y, 1) << "!!" << endl;
            printf("%d\n",tmp);
            insert(mapa[tab[i].x - tmp + 1], mapa[tab[i].x], tab[i].y, 0);
//          cerr << "Insert po x " << tab[i].x - tmp + 1 << " " << tab[i].x << " <- " << tab[i].y << endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;

int n, q;

struct query {
    int x, y;
    char a;
};
query tab[200005];
map <int,int> mapa;

const int p = 21;
int tree[1 << p][2];
int M = 1 << (p - 1);

set <pair<int,int> > S;

void insert(int left, int right, int val, int id) {
    left += M;
    right += M;
    tree[left][id] = max(tree[left][id], val);
    tree[right][id] = max(tree[right][id], val);
    while(left / 2 != right / 2) {
        if(left % 2 == 0) tree[left + 1][id] = max(tree[left + 1][id], val);
        if(right % 2 == 1) tree[right - 1][id] = max(tree[right - 1][id], val);
        left /= 2; right /= 2;
    }
}

int query(int pos, int id) {
    pos += M;
    int ans = tree[pos][id];
    while(pos) {
        ans = max(ans, tree[pos][id]);
        pos /= 2;
    }
    return ans;
}

int main() {
    scanf("%d %d", &n, &q);

    for(int i = 0; i < q; i++) {
        scanf("%d %d %c",&tab[i].x, &tab[i].y, &tab[i].a);
        mapa[tab[i].x] = mapa[tab[i].y] = 1;
    }
    mapa[n] = 1;
    int idx = 1;
    for(map <int,int> :: iterator it = mapa.begin(); it != mapa.end(); it++) {
        mapa[(*it).first] = idx++;
    }

    for(int i = 0; i < q; i++) {
        if(S.find(make_pair(tab[i].x, tab[i].y)) != S.end()) {
            printf("0\n");
            continue;
        }
        if(tab[i].a == 'U') {
            int tmp = tab[i].y - query(mapa[tab[i].x], 0);
//          cerr << "Query on " << tab[i].x << " = " << query(tab[i].x, 0) << "!!" << endl;
            printf("%d\n", tmp);
            insert(mapa[tab[i].y - tmp], mapa[tab[i].y], tab[i].x, 1);
//          cerr << "Insert po y " << tab[i].y - tmp << " " << tab[i].y << " <- " << tab[i].x << endl;
        } else {
            int tmp = tab[i].x - query(mapa[tab[i].y], 1);
//          cerr << "Query on " << tab[i].y << " = " << query(tab[i].y, 1) << "!!" << endl;
            printf("%d\n",tmp);
            insert(mapa[tab[i].x - tmp], mapa[tab[i].x], tab[i].y, 0);
//          cerr << "Insert po x " << tab[i].x - tmp << " " << tab[i].x << " <- " << tab[i].y << endl;
        }
        S.insert(make_pair(tab[i].x, tab[i].y));

    }

}


#include <bits/stdc++.h>
using namespace std;

int n, q;

struct query {
    int x, y;
    char a;
};
query tab[200005];
map <int,int> mapa;

const int p = 21;
int tree[1 << p][2];
int M = 1 << (p - 1);

void insert(int left, int right, int val, int id) {
    left += M;
    right += M;
    tree[left][id] = max(tree[left][id], val);
    tree[right][id] = max(tree[right][id], val);
    while(left / 2 != right / 2) {
        if(left % 2 == 0) tree[left + 1][id] = max(tree[left + 1][id], val);
        if(right % 2 == 1) tree[right - 1][id] = max(tree[right - 1][id], val);
        left /= 2; right /= 2;
    }
}

int query(int pos, int id) {
    pos += M;
    int ans = tree[pos][id];
    while(pos) {
        ans = max(ans, tree[pos][id]);
        pos /= 2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    scanf("%d %d", &n, &q);

    for(int i = 0; i < q; i++) {
        scanf("%d %d %c",&tab[i].x, &tab[i].y, &tab[i].a);
        mapa[tab[i].x] = mapa[tab[i].y] = 1;
    }
    mapa[n] = 1;
    int idx = 1;
    for(map <int,int> :: iterator it = mapa.begin(); it != mapa.end(); it++) {
        mapa[(*it).first] = idx++;
    }

    for(int i = 1; i < (1 << p); i++)
        tree[i][0] = tree[i][1] = 0;

    for(int i = 0; i < q; i++) {

        if(tab[i].a == 'U') {
            int tmp = tab[i].y - query(M[tab[i].x], 0);
//          cerr << query(tab[i].x, 0) << "!" << endl;
            printf("%d\n", tmp);
            insert(mapa[tab[i].y - tmp + 1], mapa[tab[i].y], tab[i].x, 1);
//          cerr << "Insert po y " << tab[i].y - tmp + 1 << " " << tab[i].y << " <- " << tab[i].x << endl;
        } else {
            int tmp = tab[i].x - query(M[tab[i].y], 1);
//          cerr << query(tab[i].y, 1) << "!!" << endl;
            printf("%d\n",tmp);
            insert(mapa[tab[i].x - tmp + 1], mapa[tab[i].x], tab[i].y, 0);
//          cerr << "Insert po x " << tab[i].x - tmp + 1 << " " << tab[i].x << " <- " << tab[i].y << endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;

int n, q;

struct query {
    int x, y;
    char a;
};
query tab[200005];
map <int,int> mapa;

const int p = 20;
int tree[1 << p][2];
int M = 1 << (p - 1);

void insert(int left, int right, int val, int id) {
    left += M;
    right += M;
    tree[left][id] = max(tree[left][id], val);
    tree[right][id] = max(tree[right][id], val);
    while(left / 2 != right / 2) {
        if(left % 2 == 0) tree[left + 1][id] = max(tree[left + 1][id], val);
        if(right % 2 == 0) tree[right - 1][id] = max(tree[right - 1][id], val);
        left /= 2; right /= 2;
    }
}

int query(int pos, int id) {
    pos += M;
    int ans = tree[pos][id];
    while(pos) {
        ans = max(ans, tree[pos][id]);
        pos /= 2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> q;

    for(int i = 0; i < q; i++) {
        cin >> tab[i].x >> tab[i].y >> tab[i].a;
        mapa[tab[i].x] = mapa[tab[i].y] = 1;
    }
    mapa[n] = 1;
    int idx = 1;
    for(map <int,int> :: iterator it = mapa.begin(); it != mapa.end(); it++) {
        mapa[(*it).first] = idx++;
    }

    for(int i = 1; i < (1 << p); i++)
        tree[i][0] = tree[i][1] = 0;

    for(int i = 0; i < q; i++) {

        if(tab[i].a == 'U') {
            int tmp = tab[i].y - query(tab[i].x, 0);
//          cerr << query(tab[i].x, 0) << "!" << endl;
            cout << tmp << endl;
            insert(mapa[tab[i].y - tmp + 1], mapa[tab[i].y], tab[i].x, 1);
//          cerr << "Insert po y " << tab[i].y - tmp + 1 << " " << tab[i].y << " <- " << tab[i].x << endl;
        } else {
            int tmp = tab[i].x - query(tab[i].y, 1);
//          cerr << query(tab[i].y, 1) << "!!" << endl;
            cout << tmp << endl;
            insert(mapa[tab[i].x - tmp + 1], mapa[tab[i].x], tab[i].y, 0);
//          cerr << "Insert po x " << tab[i].x - tmp + 1 << " " << tab[i].x << " <- " << tab[i].y << endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;

int n, q;

struct query {
    int x, y;
    char a;
};
query tab[200005];
map <int,int> mapa;

const int p = 21;
int tree[1 << p][2];
int M = 1 << (p - 1);

void insert(int left, int right, int val, int id) {
    left += M;
    right += M;
    tree[left][id] = max(tree[left][id], val);
    tree[right][id] = max(tree[right][id], val);
    while(left / 2 != right / 2) {
        if(left % 2 == 0) tree[left + 1][id] = max(tree[left + 1][id], val);
        if(right % 2 == 0) tree[right - 1][id] = max(tree[right - 1][id], val);
        left /= 2; right /= 2;
    }
}

int query(int pos, int id) {
    pos += M;
    int ans = tree[pos][id];
    while(pos) {
        ans = max(ans, tree[pos][id]);
        pos /= 2;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    scanf("%d %d", &n, &q);

    for(int i = 0; i < q; i++) {
        scanf("%d %d %c",&tab[i].x, &tab[i].y, &tab[i].a);
        mapa[tab[i].x] = mapa[tab[i].y] = 1;
    }
    mapa[n] = 1;
    int idx = 1;
    for(map <int,int> :: iterator it = mapa.begin(); it != mapa.end(); it++) {
        mapa[(*it).first] = idx++;
    }

    for(int i = 1; i < (1 << p); i++)
        tree[i][0] = tree[i][1] = 0;

    for(int i = 0; i < q; i++) {

        if(tab[i].a == 'U') {
            int tmp = tab[i].y - query(tab[i].x, 0);
//          cerr << query(tab[i].x, 0) << "!" << endl;
            printf("%d\n", tmp);
            insert(mapa[tab[i].y - tmp + 1], mapa[tab[i].y], tab[i].x, 1);
//          cerr << "Insert po y " << tab[i].y - tmp + 1 << " " << tab[i].y << " <- " << tab[i].x << endl;
        } else {
            int tmp = tab[i].x - query(tab[i].y, 1);
//          cerr << query(tab[i].y, 1) << "!!" << endl;
            printf("%d\n",tmp);
            insert(mapa[tab[i].x - tmp + 1], mapa[tab[i].x], tab[i].y, 0);
//          cerr << "Insert po x " << tab[i].x - tmp + 1 << " " << tab[i].x << " <- " << tab[i].y << endl;
        }

    }

}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define Msn(x,y) (memset((x),0,sizeof((x[0]))*(y+1)))
#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x,y) (memset((x),0x7f,sizeof((x[0]))*(y+3)))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
#define LL(x)  ((x)<<1)
#define RR(x)  ((x)<<1|1)
typedef long long ll;
using namespace std;
const int inf=1e9+7;
const int maxn=2*1e5+7;
struct node
{
    int l,r;
    int minn[2];
    int mid()
    {
        return (l+r)/2;
    }
} t[maxn*4];
map<int,int>mp;
vector<int>p;
int pos[maxn];
int dir[maxn];
int n,q;
int col[maxn],row[maxn];
bool vis[maxn];
int ans[maxn][2];
void build(int l,int r ,int id)
{
    t[id].l=l;
    t[id].r=r;
    t[id].minn[0]=t[id].minn[1]=n;
    if(l==r)
    {
        return;
    }
    int mid=t[id].mid();
    build(l,mid,LL(id));
    build(mid+1,r,RR(id));
}

void push_down(int id)
{
    for(int i=0; i<2; i++)
    {
        t[LL(id)].minn[i]=min(t[LL(id)].minn[i],t[id].minn[i]);
        t[RR(id)].minn[i]=min(t[RR(id)].minn[i],t[id].minn[i]);
    }
}

void update(int l,int r,int add,int id,int k)
{

    if(l<=t[id].l&&t[id].r<=r)
    {
        t[id].minn[k]=min(t[id].minn[k],add);
        return;
    }
    push_down(id);
    int mid=t[id].mid();
    if(l<=mid)update(l,r,add,LL(id),k);
    if(mid+1<=r)update(l,r,add,RR(id),k);
}

void query(int pos,int id)
{
    if(t[id].l==t[id].r)
    {
        ans[pos][0]=t[id].minn[0];
        ans[pos][1]=t[id].minn[1];
      //  fuck(t[id].minn[1]);
        return;
    }
    int mid=t[id].mid();
    push_down(id);
    if(pos<=mid)query(pos,LL(id));
    else query(pos,RR(id));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0; i<q; i++)
    {
        int a,b;
        char s[2];
        scanf("%d%d%s",&a,&b,s);
        pos[i]=a;
        p.push_back(a);
        p.push_back(b);
        if(s[0]=='U')dir[i]=0;
        else dir[i]=1;
    }
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0; i<p.size(); i++)mp[p[i]]=i+1;
    int sz=p.size();
    build(1,sz,1);
    for(int i=1; i<=sz; i++)ans[i][0]=ans[i][1]=n;
    for(int i=0; i<q; i++)
    {
        if(dir[i]==0)
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            query(pp,1);
            int len=ans[pp][dir[i]]-pos[i]+1;
            printf("%d\n",len);
            int d=mp[n+1-pos[i]];
            int u=mp[n+1-pos[i]-len+1];
            update(u,d,n-pos[i],1,1);
        }
        else
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            pp=mp[n+1-pos[i]];
            query(pp,1);
            int len=ans[pp][dir[i]]-(n+1-pos[i])+1;
             printf("%d\n",len);
            int r=mp[pos[i]];
            int l=mp[pos[i]-len+1];
            update(l,r,pos[i]-1,1,0);
        }
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define Msn(x,y) (memset((x),0,sizeof((x[0]))*(y+1)))
#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x,y) (memset((x),0x7f,sizeof((x[0]))*(y+3)))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
#define LL(x)  ((x)<<1)
#define RR(x)  ((x)<<1|1)
typedef long long ll;
using namespace std;
const int inf=1e9+7;
const int maxn=2*1e5+7;
struct node
{
    int l,r;
    int minn[2];
    int mid()
    {
        return (l+r)/2;
    }
}t[maxn*4];
map<int,int>mp;
vector<int>p;
int pos[maxn];
int dir[maxn];
int n,q;
int col[maxn],row[maxn];
bool vis[maxn];
int ans[maxn][2];
void build(int l,int r ,int id)
{
    t[id].l=l;
    t[id].r=r;
    t[id].minn[0]=t[id].minn[1]=n;
    if(l==r)
    {
        return;
    }
    int mid=t[id].mid();
    build(l,mid,LL(id));
    build(mid+1,r,RR(id));
}

void push_down(int id)
{
    for(int i=0;i<2;i++)
    {
        t[LL(id)].minn[i]=min(t[LL(id)].minn[i],t[id].minn[i]);
        t[RR(id)].minn[i]=min(t[RR(id)].minn[i],t[id].minn[i]);
    }
}

void update(int l,int r,int add,int id,int k)
{
    if(l<=t[id].l&&t[id].r<=r)
    {
        t[id].minn[k]=min(t[id].minn[k],add);
        return;
    }
    push_down(id);
    int mid=t[id].mid();
    if(l<=mid)update(l,r,add,LL(id),k);
    if(mid+1<=r)update(l,r,add,RR(id),k);
}

void query(int pos,int id)
{
    if(t[id].l==t[id].r)
    {
        ans[pos][0]=t[id].minn[0];
        ans[pos][1]=t[id].minn[1];
        return;
    }
    int mid=t[id].mid();
    push_down(id);
    if(pos<=mid)query(pos,LL(id));
    else query(pos,RR(id));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0;i<q;i++)
    {
        int a,b;
        char s[2];
        scanf("%d%d%s",&a,&b,s);
        pos[i]=a;
        p.push_back(a);
        p.push_back(b);
        if(s[0]=='U')dir[i]=0;
        else dir[i]=1;
    }
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0;i<p.size();i++)mp[p[i]]=i+1;
    int sz=p.size();
    build(1,sz,1);
    for(int i=1;i<=sz;i++)ans[i][0]=ans[i][1]=n;
    for(int i=0;i<q;i++)
    {
        int pp=mp[pos[i]];
        if(vis[pp])
        {
            printf("0\n");
            continue;
        }
        vis[pp]=1;
        query(pp,1);
        printf("%d\n",ans[pp][dir[i]]-pos[i]+1);
        int len=ans[pp][dir[i]]-pos[i]+1;
        if(dir[i]==0)
        {
            int d=mp[n+1-pos[i]];
            int up=d-len+1;
            int u=lower_bound(p.begin(),p.end(),up)-p.begin()+1;
            update(u,d,n-pos[i]+1,1,1);
        }
        else
        {
            int ll=pos[i]-len+1;
            int r=mp[pos[i]];
            int l=lower_bound(p.begin(),p.end(),ll)-p.begin()+1;
            update(l,r,pos[i],1,0);
        }
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define Msn(x,y) (memset((x),0,sizeof((x[0]))*(y+1)))
#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x,y) (memset((x),0x7f,sizeof((x[0]))*(y+3)))

#define acer cout<<"sb"<<endl
#define LL(x)  ((x)<<1)
#define RR(x)  ((x)<<1|1)
typedef long long ll;
using namespace std;
const int inf=1e9+7;
const int maxn=8*1e5+7;
struct node
{
    int l,r;
    int minn[2];
    int mid()
    {
        return (l+r)/2;
    }
} t[maxn*4];
map<int,int>mp;
vector<int>p;
int pos[maxn];
int dir[maxn];
int n,q;
int col[maxn],row[maxn];
bool vis[maxn];
int ans[maxn][2];
void build(int l,int r ,int id)
{
    t[id].l=l;
    t[id].r=r;
    t[id].minn[0]=t[id].minn[1]=n;
    if(l==r)
    {
        return;
    }
    int mid=t[id].mid();
    build(l,mid,LL(id));
    build(mid+1,r,RR(id));
}

void push_down(int id)
{
    for(int i=0; i<2; i++)
    {
        t[LL(id)].minn[i]=min(t[LL(id)].minn[i],t[id].minn[i]);
        t[RR(id)].minn[i]=min(t[RR(id)].minn[i],t[id].minn[i]);
    }
}

void update(int l,int r,int add,int id,int k)
{

    if(l<=t[id].l&&t[id].r<=r)
    {
        t[id].minn[k]=min(t[id].minn[k],add);
        return;
    }
    push_down(id);
    int mid=t[id].mid();
    if(l<=mid)update(l,r,add,LL(id),k);
    if(mid+1<=r)update(l,r,add,RR(id),k);
}

void query(int pos,int id)
{
    if(t[id].l==t[id].r)
    {
        ans[pos][0]=t[id].minn[0];
        ans[pos][1]=t[id].minn[1];
      //  fuck(t[id].minn[1]);
        return;
    }
    int mid=t[id].mid();
    push_down(id);
    if(pos<=mid)query(pos,LL(id));
    else query(pos,RR(id));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0; i<q; i++)
    {
        int a,b;
        char s[2];
        scanf("%d%d%s",&a,&b,s);
        pos[i]=a;
        p.push_back(a);
        p.push_back(a-1);
        p.push_back(b);
        p.push_back(b-1);
        if(s[0]=='U')dir[i]=0;
        else dir[i]=1;
    }
    p.push_back(1);
    p.push_back(n);
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0; i<p.size(); i++)mp[p[i]]=i+1;
    int sz=p.size();
    build(1,sz,1);
    for(int i=1; i<=sz; i++)ans[i][0]=ans[i][1]=n;
    for(int i=0; i<q; i++)
    {
        if(dir[i]==0)
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            query(pp,1);
            int len=ans[pp][dir[i]]-pos[i]+1;
            printf("%d\n",len);
//            fuck(n+1-pos[i]-len+1);
            int d=mp[n+1-pos[i]];
            int u=mp[n+1-pos[i]-len+1];
            update(u,d,n-pos[i],1,1);
        }
        else
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            pp=mp[n+1-pos[i]];
            query(pp,1);
            int len=ans[pp][dir[i]]-(n+1-pos[i])+1;
             printf("%d\n",len);
            int r=mp[pos[i]];
            int l=mp[pos[i]-len+1];
            update(l,r,pos[i]-1,1,0);
        }
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define Msn(x,y) (memset((x),0,sizeof((x[0]))*(y+1)))
#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x,y) (memset((x),0x7f,sizeof((x[0]))*(y+3)))

#define acer cout<<"sb"<<endl
#define LL(x)  ((x)<<1)
#define RR(x)  ((x)<<1|1)
typedef long long ll;
using namespace std;
const int inf=1e9+7;
const int maxn=2*1e5+7;
struct node
{
    int l,r;
    int minn[2];
    int mid()
    {
        return (l+r)/2;
    }
} t[maxn*4];
map<int,int>mp;
vector<int>p;
int pos[maxn];
int dir[maxn];
int n,q;
int col[maxn],row[maxn];
bool vis[maxn];
int ans[maxn][2];
void build(int l,int r ,int id)
{
    t[id].l=l;
    t[id].r=r;
    t[id].minn[0]=t[id].minn[1]=n;
    if(l==r)
    {
        return;
    }
    int mid=t[id].mid();
    build(l,mid,LL(id));
    build(mid+1,r,RR(id));
}

void push_down(int id)
{
    for(int i=0; i<2; i++)
    {
        t[LL(id)].minn[i]=min(t[LL(id)].minn[i],t[id].minn[i]);
        t[RR(id)].minn[i]=min(t[RR(id)].minn[i],t[id].minn[i]);
    }
}

void update(int l,int r,int add,int id,int k)
{

    if(l<=t[id].l&&t[id].r<=r)
    {
        t[id].minn[k]=min(t[id].minn[k],add);
        return;
    }
    push_down(id);
    int mid=t[id].mid();
    if(l<=mid)update(l,r,add,LL(id),k);
    if(mid+1<=r)update(l,r,add,RR(id),k);
}

void query(int pos,int id)
{
    if(t[id].l==t[id].r)
    {
        ans[pos][0]=t[id].minn[0];
        ans[pos][1]=t[id].minn[1];
      //  fuck(t[id].minn[1]);
        return;
    }
    int mid=t[id].mid();
    push_down(id);
    if(pos<=mid)query(pos,LL(id));
    else query(pos,RR(id));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0; i<q; i++)
    {
        int a,b;
        char s[2];
        scanf("%d%d%s",&a,&b,s);
        pos[i]=a;
        p.push_back(a);
        p.push_back(a-1);
        p.push_back(a+1);
        p.push_back(b);
        p.push_back(b-1);
        p.push_back(b+1);
        if(s[0]=='U')dir[i]=0;
        else dir[i]=1;
    }
    p.push_back(1);
    p.push_back(n);
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0; i<p.size(); i++)mp[p[i]]=i+1;
    int sz=p.size();
    build(1,sz,1);
    for(int i=1; i<=sz; i++)ans[i][0]=ans[i][1]=n;
    for(int i=0; i<q; i++)
    {
        if(dir[i]==0)
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            query(pp,1);
            int len=ans[pp][dir[i]]-pos[i]+1;
            printf("%d\n",len);
//            fuck(n+1-pos[i]-len+1);
            int d=mp[n+1-pos[i]];
            int u=mp[n+1-pos[i]-len+1];
            update(u,d,n-pos[i],1,1);
        }
        else
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            pp=mp[n+1-pos[i]];
            query(pp,1);
            int len=ans[pp][dir[i]]-(n+1-pos[i])+1;
             printf("%d\n",len);
            int r=mp[pos[i]];
            int l=mp[pos[i]-len+1];
            update(l,r,pos[i]-1,1,0);
        }
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define Msn(x,y) (memset((x),0,sizeof((x[0]))*(y+1)))
#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x,y) (memset((x),0x7f,sizeof((x[0]))*(y+3)))

#define acer cout<<"sb"<<endl
#define LL(x)  ((x)<<1)
#define RR(x)  ((x)<<1|1)
typedef long long ll;
using namespace std;
const int inf=1e9+7;
const int maxn=8*1e5+7;
struct node
{
    int l,r;
    int minn[2];
    int mid()
    {
        return (l+r)/2;
    }
} t[maxn*4];
map<int,int>mp;
vector<int>p;
int pos[maxn];
int dir[maxn];
int n,q;
int col[maxn],row[maxn];
bool vis[maxn];
int ans[maxn][2];
void build(int l,int r ,int id)
{
    t[id].l=l;
    t[id].r=r;
    t[id].minn[0]=t[id].minn[1]=n;
    if(l==r)
    {
        return;
    }
    int mid=t[id].mid();
    build(l,mid,LL(id));
    build(mid+1,r,RR(id));
}

void push_down(int id)
{
    for(int i=0; i<2; i++)
    {
        t[LL(id)].minn[i]=min(t[LL(id)].minn[i],t[id].minn[i]);
        t[RR(id)].minn[i]=min(t[RR(id)].minn[i],t[id].minn[i]);
    }
}

void update(int l,int r,int add,int id,int k)
{

    if(l<=t[id].l&&t[id].r<=r)
    {
        t[id].minn[k]=min(t[id].minn[k],add);
        return;
    }
    push_down(id);
    int mid=t[id].mid();
    if(l<=mid)update(l,r,add,LL(id),k);
    if(mid+1<=r)update(l,r,add,RR(id),k);
}

void query(int pos,int id)
{
    if(t[id].l==t[id].r)
    {
        ans[pos][0]=t[id].minn[0];
        ans[pos][1]=t[id].minn[1];
      //  fuck(t[id].minn[1]);
        return;
    }
    int mid=t[id].mid();
    push_down(id);
    if(pos<=mid)query(pos,LL(id));
    else query(pos,RR(id));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0; i<q; i++)
    {
        int a,b;
        char s[2];
        scanf("%d%d%s",&a,&b,s);
        pos[i]=a;
        p.push_back(a);
        p.push_back(a+1);
        p.push_back(b);
        p.push_back(b+1);
        if(s[0]=='U')dir[i]=0;
        else dir[i]=1;
    }
    p.push_back(1);
    p.push_back(n);
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0; i<p.size(); i++)mp[p[i]]=i+1;
    int sz=p.size();
    build(1,sz,1);
    for(int i=1; i<=sz; i++)ans[i][0]=ans[i][1]=n;
    for(int i=0; i<q; i++)
    {
        if(dir[i]==0)
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            query(pp,1);
            int len=ans[pp][dir[i]]-pos[i]+1;
            printf("%d\n",len);
//            fuck(n+1-pos[i]-len+1);
            int d=mp[n+1-pos[i]];
            int u=mp[n+1-pos[i]-len+1];
            update(u,d,n-pos[i],1,1);
        }
        else
        {
            int pp=mp[pos[i]];
            if(vis[pp])
            {
                printf("0\n");
                continue;
            }
            vis[pp]=1;
            pp=mp[n+1-pos[i]];
            query(pp,1);
            int len=ans[pp][dir[i]]-(n+1-pos[i])+1;
             printf("%d\n",len);
            int r=mp[pos[i]];
            int l=mp[pos[i]-len+1];
            update(l,r,pos[i]-1,1,0);
        }
    }
    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>

#define Msn(x,y) (memset((x),0,sizeof((x[0]))*(y+1)))
#define msn(x) (memset((x),0,sizeof((x))))
#define msx(x,y) (memset((x),0x7f,sizeof((x[0]))*(y+3)))
#define fuck(x) cerr << #x << " <- " << x << endl
#define acer cout<<"sb"<<endl
#define LL(x)  ((x)<<1)
#define RR(x)  ((x)<<1|1)
typedef long long ll;
using namespace std;
const int inf=1e9+7;
const int maxn=2*1e5+7;
struct node
{
    int l,r;
    int minn[2];
    int mid()
    {
        return (l+r)/2;
    }
}t[maxn*4];
map<int,int>mp;
vector<int>p;
int pos[maxn];
int dir[maxn];
int n,q;
int col[maxn],row[maxn];
bool vis[maxn];
int ans[maxn][2];
void build(int l,int r ,int id)
{
    t[id].l=l;
    t[id].r=r;
    t[id].minn[0]=t[id].minn[1]=n;
    if(l==r)
    {
        return;
    }
    int mid=t[id].mid();
    build(l,mid,LL(id));
    build(mid+1,r,RR(id));
}

void push_down(int id)
{
    for(int i=0;i<2;i++)
    {
        t[LL(id)].minn[i]=min(t[LL(id)].minn[i],t[id].minn[i]);
        t[RR(id)].minn[i]=min(t[RR(id)].minn[i],t[id].minn[i]);
    }
}

void update(int l,int r,int add,int id,int k)
{
    if(l<=t[id].l&&t[id].r<=r)
    {
        t[id].minn[k]=min(t[id].minn[k],add);
        return;
    }
    push_down(id);
    int mid=t[id].mid();
    if(l<=mid)update(l,r,add,LL(id),k);
    if(mid+1<=r)update(l,r,add,RR(id),k);
}

void query(int pos,int id)
{
    if(t[id].l==t[id].r)
    {
        ans[pos][0]=t[id].minn[0];
        ans[pos][1]=t[id].minn[1];
        return;
    }
    int mid=t[id].mid();
    push_down(id);
    if(pos<=mid)query(pos,LL(id));
    else query(pos,RR(id));
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0;i<q;i++)
    {
        int a,b;
        char s[2];
        scanf("%d%d%s",&a,&b,s);
        pos[i]=a;
        p.push_back(a);
        p.push_back(b);
        if(s[0]=='U')dir[i]=0;
        else dir[i]=1;
    }
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    for(int i=0;i<p.size();i++)mp[p[i]]=i+1;
    int sz=p.size();
    build(1,sz,1);
    for(int i=1;i<=sz;i++)ans[i][0]=ans[i][1]=n;
    for(int i=0;i<q;i++)
    {
        int pp=mp[pos[i]];
        if(vis[pp])
        {
            printf("0\n");
            continue;
        }
        vis[pp]=1;
        query(pp,1);
        printf("%d\n",ans[i][dir[i]]-i+1);
        int len=ans[i][dir[i]]-i+1;
        if(dir[i]==0)
        {
            int d=mp[n+1-pos[i]];
            int up=d-len+1;
            int u=lower_bound(p.begin(),p.end(),up)-p.begin();
            update(u,d,n-pos[i]+1,1,1);
        }
        else
        {
            int ll=pos[i]-len+1;
            int r=mp[pos[i]];
            int l=lower_bound(p.begin(),p.end(),ll)-p.begin();
            update(l,r,pos[i],1,0);
        }
    }
    return 0;
}


/*input
10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

9
1
10
6
0
2
*/

/*
ID: aayushg1
LANG: C++
PROG: 310C
*/

#include <bits/stdc++.h>  //includes everything, supported in CF, USACO

#define DEBUG
#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define sp << ' ' <<
#define inf (ll)2147483648
#define maxn 100010
#define bitSize2 7000000
using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;

ll tree[bitSize2];   //make vectors to save space
ll lazy[bitSize2];   //represents the value that each element is being decreased by
pii kids[bitSize2];
ll n, q;

map<ll, ll> seen;
ll avail = 2;

ll getKids(ll at, ll which){
    if(kids[at].f == -1){
        kids[at] = mp(avail, avail + 1);
        avail += 2;
    }
    if(which%2 == 0)return kids[at].f;
    else return kids[at].s;
}

ll getTree(ll node){
    return tree[node];
}

ll getLazy(ll node){
    return lazy[node];
}

ll setTree(ll node, ll val){
    tree[node] = val;
}

ll setLazy(ll node, ll val){
    lazy[node] = val;
}

void lazyShiftMax(ll node, ll start, ll finish){
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    setTree(node, max(getTree(node), getLazy(node)));
    if(start != finish){    //not a bottommost node
        setLazy(getKids(node, 0), max(getLazy(getKids(node, 0)), getLazy(node)));
        setLazy(getKids(node, 1), max(getLazy(getKids(node, 1)), getLazy(node)));
    }
    setLazy(node, 0);
}

void changeValueMax(ll from, ll to, ll value, ll node, ll start = 1, ll finish = inf){          //range start, range end, node #, range of node start, range of node end
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish){ //put lazy
        setLazy(node, max(getLazy(node), value));
    }
    // cout << from sp to sp value sp start sp finish << " change\n";
    lazyShiftMax(node, start, finish);
    if((from<=start&&to>=finish) || to < start || from > finish)          //aded last 2 cases in case out of range
        return;
    changeValueMax(from, to, value, getKids(node, 0), start, mid);
    changeValueMax(from, to, value, getKids(node, 1), mid+1, finish);
    setTree(node, max(getTree(getKids(node, 0)), getTree(getKids(node, 1))));                       //b/c of lazy shift
}

ll findMax(ll from, ll to, ll node, ll start = 1, ll finish = inf){          //range start, range end, node #, range of node start, range of node end
    lazyShiftMax(node, start, finish);
    // cout << from sp to sp dir sp node sp getTree(node) sp endl;
    if(from > finish || to < start)return 0;
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish)
        return getTree(node);
    return max(findMax(from, to, getKids(node, 0), start, mid), findMax(from, to, getKids(node, 1), mid+1, finish));
}

ll initNodeMax(){        //when adapting, make sure to ensure initial values are inf/0
    // fill(tree[0], tree[0] + bitSize2, 0);    //map, defailt return above is just 0.
    // fill(tree[1], tree[1] + bitSize2, 0);
    // fill(lazy[0], lazy[0] + bitSize2, 0);
    // fill(lazy[1], lazy[1] + bitSize2, 0);
    fill(kids, kids + bitSize2, mp(-1, -1));
}

void check(ll a, ll b, char dir){
    // if(seen.count(a) > 0){
    //     cout << "0\n";
    //     return;
    // }
    // seen[a] = 1;
	ll c;
	if(dir=='L')c = 0;
	else c = 1;
	// cerr << a sp b sp c sp endl;
	if(c==0){								//CHECK THAT NOT PREVIOUSLY USED AS A L/U
		ll upto = findMax(b, b, 1-c);
		changeValueMax(upto, a, b, c);
        // changeValueMax(a, a, b, c);
        changeValueMax(b, b, a, 1-c);
		cout << a-upto << endl;
	}
	else if(c==1){
		ll upto = findMax(a, a, 1-c);
		changeValueMax(upto, b, a, c);
        // changeValueMax(b, b, a, c);
        changeValueMax(a, a, b, 1-c);
		cout << b-upto << endl;
	}
	return;
}

int main(){					//more correctish, but TLE since (n log^2 n), not (n log n) on max case.
	// freopen ("haybales.in","r",stdin);
	ios_base::sync_with_stdio(false);
	ios::sync_with_stdio(false);
	// freopen ("haybales.out","w",stdout);
	cin >> n >> q;
	initNodeMax();
	for(ll i = 0; i < q; ++i){
		ll a, b;
		char c;
		cin >> a >> b >> c;
		check(a, b, c);
        if(avail > bitSize2){
            cout << "BAD\n";
            cerr << "BAD\n";
            return 0;
        }
	}
}


/*input
10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

6 5
3 4 U
6 1 L
2 5 L
1 6 U
4 3 U
*/

/*
ID: aayushg1
LANG: C++
PROG: 310C
*/

#include <bits/stdc++.h>  //includes everything, supported in CF, USACO

#define DEBUG
#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define sp << ' ' <<
#define inf 2000000000
#define maxn 100010
#define bitSize 262144
#define bitSize2 bitSize*2
using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;

ll tree[bitSize2];
ll lazy[bitSize2];   //represents the value that each element is being decreased by
ll values[bitSize];
ll n, q;

map<pii, int> treeMap;  //large index -> small index
map<pii, int> lazyMap;
map<int, int> seen;

int c = 0;
ll getTree(ll dir, ll node){
    pii obj = mp(dir, node);
    if(treeMap.count(obj)==0){
        treeMap[obj] = c++;
    }
    return tree[treeMap[obj]];
}

ll getLazy(ll dir, ll node){
    pii obj = mp(dir, node);
    if(lazyMap.count(obj)==0){
        lazyMap[obj] = c++;
    }
    return lazy[lazyMap[obj]];
}

ll setTree(ll dir, ll node, ll val){
    pii obj = mp(dir, node);
    tree[treeMap[obj]] = val;
}

ll setLazy(ll dir, ll node, ll val){
    pii obj = mp(dir, node);
    lazy[lazyMap[obj]] = val;
}

void lazyShiftMax(ll node, ll start, ll finish, ll dir){
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    setTree(dir, node, max(getTree(dir, node), getLazy(dir, node)));
    if(node < bitSize){
        setLazy(dir, node*2, max(getLazy(dir, node * 2), getLazy(dir, node)));
        setLazy(dir, node*2+1, max(getLazy(dir, node * 2 + 1), getLazy(dir, node)));
    }
    setLazy(dir, node, 0);
}

void changeValueMax(ll from, ll to, ll value, ll dir, ll node = 1, ll start = 1, ll finish = bitSize){          //range start, range end, node #, range of node start, range of node end
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish){ //put lazy
        setLazy(dir, node, max(getLazy(dir, node), value));
    }
    lazyShiftMax(node, start, finish, dir);
    if((from<=start&&to>=finish) || to < start || from > finish)          //aded last 2 cases in case out of range
        return;
    // cout << from sp to sp value sp start sp finish << " change\n";
    changeValueMax(from, to, value, dir, node*2, start, mid);
    changeValueMax(from, to, value, dir, node*2+1, mid+1, finish);
    setTree(dir, node, max(getTree(dir, 2 * node), getTree(dir, 2 * node + 1)));                       //b/c of lazy shift
}

ll findMax(ll from, ll to, ll dir, ll node = 1, ll start = 1, ll finish = bitSize){          //range start, range end, node #, range of node start, range of node end
    lazyShiftMax(node, start, finish, dir);
    if(from > finish || to < start)return 0;
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish)
        return getTree(dir, node);
    // cout << from sp to sp dir sp node sp getTree(dir, node) sp endl;
    return max(findMax(from, to, dir, node*2, start, mid), findMax(from, to, dir, node*2+1, mid+1, finish));
}

ll initNodeMax(ll node = 1){        //when adapting, make sure to ensure initial values are inf/0
    // fill(tree[0], tree[0] + bitSize2, 0);    //map, defailt return above is just 0.
    // fill(tree[1], tree[1] + bitSize2, 0);
    // fill(lazy[0], lazy[0] + bitSize2, 0);
    // fill(lazy[1], lazy[1] + bitSize2, 0);
}

// ll out(){
//     for(ll i = 0; i < n; ++i) cout << tree[0][bitSize+i] << " ";
//     cout << "\n";
//     for(ll i = 0; i < n; ++i) cout << tree[1][bitSize+i] << " ";
//     cout << "\n";
// }

void check(ll a, ll b, char dir){
    if(seen.count(a) > 0){
        cout << "0\n";
        return;
    }
    seen[a] = 1;
	ll c;
	if(dir=='L')c = 0;
	else c = 1;
	// cerr << a sp b sp c sp endl;
	if(c==0){								//CHECK THAT NOT PREVIOUSLY USED AS A L/U
		ll upto = findMax(b, b, 1-c);
		changeValueMax(upto, a, b, c);
		changeValueMax(a, a, b, c);
		cout << a-upto << endl;
	}
	else if(c==1){
		ll upto = findMax(a, a, 1-c);
		changeValueMax(upto, b, a, c);
		changeValueMax(b, b, a, c);
		cout << b-upto << endl;
	}
	return;
}

int main(){					  						//CHECK THAT NOT PREVIOUSLY USED AS A L/U
	// freopen ("haybales.in","r",stdin);
	// ios_base::sync_with_stdio(false);
	// ios::sync_with_stdio(false);
	// freopen ("haybales.out","w",stdout);
	cin >> n >> q;
	initNodeMax();
	for(ll i = 0; i < q; ++i){
		ll a, b;
		char c;
		cin >> a >> b >> c;
		check(a, b, c);
	}
}


/*input
10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

9
1
10
6
0
2
*/

/*
ID: aayushg1
LANG: C++
PROG: 310C
*/

#include <bits/stdc++.h>  //includes everything, supported in CF, USACO

#define DEBUG
#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define sp << ' ' <<
#define inf 1073741824
#define maxn 200010
#define bitSize2 16005000
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int tree[bitSize2];   //make vectors to save space
int lazy[bitSize2];   //represents the value that each element is being decreased by
int kids[bitSize2][2];
int n, q;

map<int, int> seen;
int avail = 2;

int getKids(int at, int which){
    if(kids[at][which] == -1){
        kids[at][which] = avail;
        ++avail;
    }
    return kids[at][which];
}

int getTree(int node){return tree[node];}   //legacy methods
int getLazy(int node){return lazy[node];}
int setTree(int node, int val){tree[node] = val;}
int setLazy(int node, int val){lazy[node] = val;}

void lazyShiftMax(int node, int start, int finish){
    int mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    setTree(node, max(getTree(node), getLazy(node)));
    if(start != finish){    //not a bottommost node
        setLazy(getKids(node, 0), max(getLazy(getKids(node, 0)), getLazy(node)));
        setLazy(getKids(node, 1), max(getLazy(getKids(node, 1)), getLazy(node)));
    }
    setLazy(node, 0);
}

void changeValueMax(int from, int to, int value, int node, int start = 1, int finish = inf){          //range start, range end, node #, range of node start, range of node end
    int mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish){ //put lazy
        setLazy(node, max(getLazy(node), value));
        return;
    }
    // cout << from sp to sp value sp start sp finish << " change\n";
    if(to < start || from > finish)          //aded last 2 cases in case out of range
        return;
    lazyShiftMax(node, start, finish);
    changeValueMax(from, to, value, getKids(node, 0), start, mid);
    changeValueMax(from, to, value, getKids(node, 1), mid+1, finish);
    setTree(node, max(getTree(getKids(node, 0)), getTree(getKids(node, 1))));                       //b/c of lazy shift
}

int findMax(int from, int to, int node, int start = 1, int finish = inf){          //range start, range end, node #, range of node start, range of node end
    // cout << from sp to sp dir sp node sp getTree(node) sp endl;
    if(from > finish || to < start)return 0;
    lazyShiftMax(node, start, finish);
    int mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish)
        return getTree(node);
    return max(findMax(from, to, getKids(node, 0), start, mid), findMax(from, to, getKids(node, 1), mid+1, finish));
}

int initNodeMax(){        //when adapting, make sure to ensure initial values are inf/0
    // fiint(tree[0], tree[0] + bitSize2, 0);    //map, defailt return above is just 0.
    // fiint(tree[1], tree[1] + bitSize2, 0);
    // fiint(lazy[0], lazy[0] + bitSize2, 0);
    // fiint(lazy[1], lazy[1] + bitSize2, 0);
    fill(kids[0], kids[0] + bitSize2, -1);
    fill(kids[1], kids[1] + bitSize2, -1);
}

void check(int a, int b, char dir){
    if(seen.count(a) > 0){
        cout << "0\n";
        return;
    }
    seen[a] = 1;
	int c;
	if(dir=='L')c = 0;
	else c = 1;
	// cerr << a sp b sp c sp endl;
	if(c==0){								//CHECK THAT NOT PREVIOUSLY USED AS A L/U
		int upto = findMax(b, b, 1-c);
		changeValueMax(upto, a, b, c);
        // changeValueMax(a, a, b, c); useless
        // changeValueMax(b, b, a, 1-c);    //do this, or seen map
		cout << a-upto << endl;
	}
	else if(c==1){
		int upto = findMax(a, a, 1-c);
		changeValueMax(upto, b, a, c);
        // changeValueMax(b, b, a, c); useless
        // changeValueMax(a, a, b, 1-c);
		cout << b-upto << endl;
	}
	return;
}

int main(){					//more correctish, but RTE, O(n log n), case 28 runs out of memory on 16M nodes.
	// freopen ("segtree.in","r",stdin);
	ios_base::sync_with_stdio(false);
	ios::sync_with_stdio(false);
	// freopen ("segtree.out","w",stdout);
	cin >> n >> q;
	initNodeMax();
	for(int i = 0; i < q; ++i){
		int a, b;
		char c;
		cin >> a >> b >> c;
		check(a, b, c);
        if(avail > bitSize2){
            cerr << "";
            cout << i;
            cout << "BAD\n";
            cerr << "";
            return 0;
        }
	}
}

//wrong answer 163918th numbers differ - expected: '3292', found: '-973001281'
//wrong output format Expected integer, but "176516BAD" found
//fixed - should only assign one kid array index at a time, not 2, and shift after return


/*input
10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

9
1
10
6
0
2
*/

/*
ID: aayushg1
LANG: C++
PROG: 310C
*/

#include <bits/stdc++.h>  //includes everything, supported in CF, USACO

#define DEBUG
#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define sp << ' ' <<
#define inf 1073741824
#define maxn 200010
#define bitSize2 15800000
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int tree[bitSize2];   //make vectors to save space
int lazy[bitSize2];   //represents the value that each element is being decreased by
int kids[bitSize2][2];
int n, q;

map<int, bool> seen;
int avail = 2;

int getKids(int at, int which){
    if(kids[at][which] == -1){
        kids[at][which] = avail;
        ++avail;
    }
    return kids[at][which];
}

int getTree(int node){return tree[node];}   //legacy methods
int getLazy(int node){return lazy[node];}
int setTree(int node, int val){tree[node] = val;}
int setLazy(int node, int val){lazy[node] = val;}

// void lazyShiftMax(int node, int start, int finish){
//     int mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
//     setTree(node, max(getTree(node), getLazy(node)));
//     if(start != finish && getLazy(node) > 0){    //not a bottommost node
//         setLazy(getKids(node, 0), max(getLazy(getKids(node, 0)), getLazy(node)));
//         setLazy(getKids(node, 1), max(getLazy(getKids(node, 1)), getLazy(node)));
//     }
//     setLazy(node, 0);
// }

void changeValueMax(int from, int to, int value, int node, int start = 1, int finish = inf){          //range start, range end, node #, range of node start, range of node end
    int mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish){ //put lazy
        setLazy(node, max(getLazy(node), value));
        setTree(node, max(getTree(node), getLazy(node)));
        // cout << from sp to sp node sp value sp start sp finish << " change\n";
        return;
    }
    // cout << from sp to sp value sp start sp finish << " change\n";
    if(to < start || from > finish)          //aded last 2 cases in case out of range
        return;
    // lazyShiftMax(node, start, finish);
    // int toSet = getTree(node);
    if(to >= start && from <= mid){
        changeValueMax(from, to, value, getKids(node, 0), start, mid);
        // toSet = max(toSet, getTree(getKids(node, 0)));
    }
    if(to >= mid+1 && from <= finish){
        changeValueMax(from, to, value, getKids(node, 1), mid+1, finish);
        // toSet = max(toSet, getTree(getKids(node, 1)));
    }
    // setTree(node, toSet);                       //b/c of lazy shift
}

int findMax(int from, int node, int start = 1, int finish = inf){          //range start, range end, node #, range of node start, range of node end
    // cout << from sp to sp dir sp node sp getTree(node) sp endl;
    if(from > finish || from < start)return 0;
    // lazyShiftMax(node, start, finish);
    int mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&from>=finish)
        return getTree(node);
    int toReturn = getTree(node);
    if(from <= mid && from >= start){
        // cout sp node << " -> " << getKids(node, 0) sp endl;
        toReturn = max(toReturn, findMax(from, getKids(node, 0), start, mid));
    }
    if(from <= finish && from >= mid + 1){
        // cout sp node << " -> " << getKids(node, 1) sp endl;
        toReturn = max(toReturn, findMax(from, getKids(node, 1), mid+1, finish));
    }
    // cout << from sp node sp toReturn sp start sp finish sp " query " << endl;
    return toReturn;
    // return max(findMax(from, to, getKids(node, 0), start, mid), findMax(from, to, getKids(node, 1), mid+1, finish));
}

int initNodeMax(){        //when adapting, make sure to ensure initial values are inf/0
    // fiint(tree[0], tree[0] + bitSize2, 0);    //map, defailt return above is just 0.
    // fiint(tree[1], tree[1] + bitSize2, 0);
    // fiint(lazy[0], lazy[0] + bitSize2, 0);
    // fiint(lazy[1], lazy[1] + bitSize2, 0);
    fill(kids[0], kids[0] + bitSize2, -1);
    fill(kids[1], kids[1] + bitSize2, -1);
}

void check(int a, int b, char dir){
    if(seen.count(a) > 0){
        cout << "0\n";
        return;
    }
    seen[a] = 1;
	int c;
	if(dir=='L')c = 0;
	else c = 1;
	// cerr << a sp b sp c sp endl;
	if(c==0){								//CHECK THAT NOT PREVIOUSLY USED AS A L/U
		int upto = findMax(b, 1-c);
		changeValueMax(upto, a, b, c);
        // changeValueMax(a, a, b, c); useless
        // changeValueMax(b, b, a, 1-c);    //do this, or seen map
		cout << a-upto << endl;
	}
	else if(c==1){
		int upto = findMax(a, 1-c);
		changeValueMax(upto, b, a, c);
        // changeValueMax(b, b, a, c); useless
        // changeValueMax(a, a, b, 1-c);
		cout << b-upto << endl;
	}
	return;
}

int main(){					//more correctish, but RTE, O(n log n), case 28 runs out of memory on 16M nodes.
	// freopen ("segtree.in","r",stdin);
	ios_base::sync_with_stdio(false);
	ios::sync_with_stdio(false);
	// freopen ("segtree.out","w",stdout);
	cin >> n >> q;
	initNodeMax();
	for(int i = 0; i < q; ++i){
		int a, b;
		char c;
		cin >> a >> b >> c;
		check(a, b, c);
        if(avail >= bitSize2){
            cerr << "";
            cout << i;
            cout << "BAD\n";
            cerr << "";
            return 0;
        }
	}
}

//wrong answer 163918th numbers differ - expected: '3292', found: '-973001281'
//wrong output format Expected integer, but "176516BAD" found
//fixed - should only assign one kid array index at a time, not 2, and shift after return
//wrong answer 164178th numbers differ - expected: '16861', found: '-488893609'
//wrong answer 164120th numbers differ - expected: '503', found: '-521253971'
//wrong answer 161802nd numbers differ - expected: '91963', found: '-411924'
//wrong answer 162256th numbers differ - expected: '39483', found: '-373904301'


/*input
1000000000 2
500000000 500000001 U
750000000 250000001 L

10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

6 5
3 4 U
6 1 L
2 5 L
1 6 U
4 3 U
*/

/*
ID: aayushg1
LANG: C++
PROG: 310C
*/

#include <bits/stdc++.h>  //includes everything, supported in CF, USACO

#define DEBUG
#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define sp << ' ' <<
#define inf (ll)2147483648
#define maxn 100010
#define bitSize 2097152
#define bitSize2 bitSize*2
using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;

ll tree[2][bitSize2];
ll lazy[2][bitSize2];   //represents the value that each element is being decreased by
pii kids[bitSize2];
ll n, q;

// map<pii, ll> treeMap;  //large index -> small index
// map<pii, ll> lazyMap;
map<ll, ll> seen;

ll c = 2;

ll getKids(ll at, ll which){
    if(kids[at].f == -1){
        kids[at] = mp(c, c + 1);
        c += 2;
    }
    if(which%2 == 0)return kids[at].f;
    else return kids[at].s;
}

ll getTree(ll dir, ll node){
    return tree[dir][node];
}

ll getLazy(ll dir, ll node){
    return lazy[dir][node];
}

ll setTree(ll dir, ll node, ll val){
    tree[dir][node] = val;
}

ll setLazy(ll dir, ll node, ll val){
    lazy[dir][node] = val;
}

void lazyShiftMax(ll node, ll start, ll finish, ll dir){
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    setTree(dir, node, max(getTree(dir, node), getLazy(dir, node)));
    if(node < bitSize){
        setLazy(dir, getKids(node, 0), max(getLazy(dir, getKids(node, 0)), getLazy(dir, node)));
        setLazy(dir, getKids(node, 1), max(getLazy(dir, getKids(node, 1)), getLazy(dir, node)));
    }
    setLazy(dir, node, 0);
}

void changeValueMax(ll from, ll to, ll value, ll dir, ll node = 1, ll start = 1, ll finish = inf){          //range start, range end, node #, range of node start, range of node end
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish){ //put lazy
        setLazy(dir, node, max(getLazy(dir, node), value));
    }
    // cout << from sp to sp value sp start sp finish << " change\n";
    lazyShiftMax(node, start, finish, dir);
    if((from<=start&&to>=finish) || to < start || from > finish)          //aded last 2 cases in case out of range
        return;
    changeValueMax(from, to, value, dir, getKids(node, 0), start, mid);
    changeValueMax(from, to, value, dir, getKids(node, 1), mid+1, finish);
    setTree(dir, node, max(getTree(dir, getKids(node, 0)), getTree(dir, getKids(node, 1))));                       //b/c of lazy shift
}

ll findMax(ll from, ll to, ll dir, ll node = 1, ll start = 1, ll finish = inf){          //range start, range end, node #, range of node start, range of node end
    lazyShiftMax(node, start, finish, dir);
    // cout << from sp to sp dir sp node sp getTree(dir, node) sp endl;
    if(from > finish || to < start)return 0;
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish)
        return getTree(dir, node);
    return max(findMax(from, to, dir, getKids(node, 0), start, mid), findMax(from, to, dir, getKids(node, 1), mid+1, finish));
}

ll initNodeMax(ll node = 1){        //when adapting, make sure to ensure initial values are inf/0
    // fill(tree[0], tree[0] + bitSize2, 0);    //map, defailt return above is just 0.
    // fill(tree[1], tree[1] + bitSize2, 0);
    // fill(lazy[0], lazy[0] + bitSize2, 0);
    // fill(lazy[1], lazy[1] + bitSize2, 0);
    fill(kids, kids + bitSize2, mp(-1, -1));
}

void check(ll a, ll b, char dir){
    if(seen.count(a) > 0){
        cout << "0\n";
        return;
    }
    seen[a] = 1;
	ll c;
	if(dir=='L')c = 0;
	else c = 1;
	// cerr << a sp b sp c sp endl;
	if(c==0){								//CHECK THAT NOT PREVIOUSLY USED AS A L/U
		ll upto = findMax(b, b, 1-c);
		changeValueMax(upto, a, b, c);
		cout << a-upto << endl;
	}
	else if(c==1){
		ll upto = findMax(a, a, 1-c);
		changeValueMax(upto, b, a, c);
		cout << b-upto << endl;
	}
	return;
}

int main(){					//more correctish, but TLE since (n log^2 n), not (n log n) on max case.
	// freopen ("haybales.in","r",stdin);
	// ios_base::sync_with_stdio(false);
	// ios::sync_with_stdio(false);
	// freopen ("haybales.out","w",stdout);
	cin >> n >> q;
	initNodeMax();
	for(ll i = 0; i < q; ++i){
		ll a, b;
		char c;
		cin >> a >> b >> c;
		check(a, b, c);
	}
}


/*input
1000000000 2
500000000 500000001 U
750000000 250000001 L

10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

6 5
3 4 U
6 1 L
2 5 L
1 6 U
4 3 U
*/

/*
ID: aayushg1
LANG: C++
PROG: 310C
*/

#include <bits/stdc++.h>  //includes everything, supported in CF, USACO

#define DEBUG
#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define sp << ' ' <<
#define inf (ll)2147483648
#define maxn 100010
#define bitSize 8388608
#define bitSize2 bitSize*2
using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;

ll tree[2][bitSize2];
ll lazy[2][bitSize2];   //represents the value that each element is being decreased by
ll values[bitSize];
pii kids[bitSize2];
ll n, q;

// map<pii, ll> treeMap;  //large index -> small index
// map<pii, ll> lazyMap;
map<ll, ll> seen;

ll c = 2;

ll getKids(ll at, ll which){
    if(kids[at].f == -1){
        kids[at] = mp(c, c + 1);
        c += 2;
    }
    if(which%2 == 0)return kids[at].f;
    else return kids[at].s;
}

ll getTree(ll dir, ll node){
    return tree[dir][node];
}

ll getLazy(ll dir, ll node){
    return lazy[dir][node];
}

ll setTree(ll dir, ll node, ll val){
    tree[dir][node] = val;
}

ll setLazy(ll dir, ll node, ll val){
    lazy[dir][node] = val;
}

void lazyShiftMax(ll node, ll start, ll finish, ll dir){
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    setTree(dir, node, max(getTree(dir, node), getLazy(dir, node)));
    if(node < bitSize){
        setLazy(dir, getKids(node, 0), max(getLazy(dir, getKids(node, 0)), getLazy(dir, node)));
        setLazy(dir, getKids(node, 1), max(getLazy(dir, getKids(node, 1)), getLazy(dir, node)));
    }
    setLazy(dir, node, 0);
}

void changeValueMax(ll from, ll to, ll value, ll dir, ll node = 1, ll start = 1, ll finish = inf){          //range start, range end, node #, range of node start, range of node end
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish){ //put lazy
        setLazy(dir, node, max(getLazy(dir, node), value));
    }
    // cout << from sp to sp value sp start sp finish << " change\n";
    lazyShiftMax(node, start, finish, dir);
    if((from<=start&&to>=finish) || to < start || from > finish)          //aded last 2 cases in case out of range
        return;
    changeValueMax(from, to, value, dir, getKids(node, 0), start, mid);
    changeValueMax(from, to, value, dir, getKids(node, 1), mid+1, finish);
    setTree(dir, node, max(getTree(dir, getKids(node, 0)), getTree(dir, getKids(node, 1))));                       //b/c of lazy shift
}

ll findMax(ll from, ll to, ll dir, ll node = 1, ll start = 1, ll finish = inf){          //range start, range end, node #, range of node start, range of node end
    lazyShiftMax(node, start, finish, dir);
    // cout << from sp to sp dir sp node sp getTree(dir, node) sp endl;
    if(from > finish || to < start)return 0;
    ll mid = (start + finish ) / 2;            //takes floor, results in the endof the first range and one less than the start of the second range
    if(from<=start&&to>=finish)
        return getTree(dir, node);
    return max(findMax(from, to, dir, getKids(node, 0), start, mid), findMax(from, to, dir, getKids(node, 1), mid+1, finish));
}

ll initNodeMax(ll node = 1){        //when adapting, make sure to ensure initial values are inf/0
    // fill(tree[0], tree[0] + bitSize2, 0);    //map, defailt return above is just 0.
    // fill(tree[1], tree[1] + bitSize2, 0);
    // fill(lazy[0], lazy[0] + bitSize2, 0);
    // fill(lazy[1], lazy[1] + bitSize2, 0);
    fill(kids, kids + bitSize2, mp(-1, -1));
}

void check(ll a, ll b, char dir){
    if(seen.count(a) > 0){
        cout << "0\n";
        return;
    }
    seen[a] = 1;
	ll c;
	if(dir=='L')c = 0;
	else c = 1;
	// cerr << a sp b sp c sp endl;
	if(c==0){								//CHECK THAT NOT PREVIOUSLY USED AS A L/U
		ll upto = findMax(b, b, 1-c);
		changeValueMax(upto, a, b, c);
		cout << a-upto << endl;
	}
	else if(c==1){
		ll upto = findMax(a, a, 1-c);
		changeValueMax(upto, b, a, c);
		cout << b-upto << endl;
	}
	return;
}

int main(){					//more correctish, but TLE since (n log^2 n), not (n log n) on max case.
	// freopen ("haybales.in","r",stdin);
	// ios_base::sync_with_stdio(false);
	// ios::sync_with_stdio(false);
	// freopen ("haybales.out","w",stdout);
	cin >> n >> q;
	initNodeMax();
	for(ll i = 0; i < q; ++i){
		ll a, b;
		char c;
		cin >> a >> b >> c;
		check(a, b, c);
	}
}