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

const int MAXN = 2E5 + 10;

int x[MAXN], y[MAXN];
char dir[MAXN];
bool done[MAXN];

struct SegTree {
	int st[MAXN * 4];
	void modify(int id, int l, int r, int qL, int qR, int val) {
		if (qL <= l && r <= qR) {
			st[id] = max(st[id], val);
		} else {
			int m = (l + r) >> 1;
			if (qL <= m) modify(id << 1, l, m, qL, qR, val);
			if (m < qR) modify(id << 1 | 1, m + 1, r, qL, qR, val);
		}
	}
	int query(int id, int l, int r, int p) {
		if (l == r) {
			return st[id];
		} else {
			int m = (l + r) >> 1;
			if (p <= m) return max(st[id], query(id << 1, l, m, p));
			else return max(st[id], query(id << 1 | 1, m + 1, r, p));
		}
	}
} up, lft;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, q; cin >> n >> q;
	vector<int> xVal = { 0 }, yVal = { 0 };
	for (int i = 0; i < q; i++) {
		cin >> x[i] >> y[i] >> dir[i];
		xVal.push_back(x[i]), yVal.push_back(y[i]);
	}
	sort(xVal.begin(), xVal.end()), sort(yVal.begin(), yVal.end());
	xVal.resize(unique(xVal.begin(), xVal.end()) - xVal.begin());
	yVal.resize(unique(yVal.begin(), yVal.end()) - yVal.begin());
	for (int i = 0; i < q; i++) {
		x[i] = (int)(lower_bound(xVal.begin(), xVal.end(), x[i]) - xVal.begin());
		y[i] = (int)(lower_bound(yVal.begin(), yVal.end(), y[i]) - yVal.begin());
	}
	for (int i = 0; i < q; i++) {
		if (done[x[i]]) {
			cout << "0\n";
		} else {
			done[x[i]] = true;
			if (dir[i] == 'U') {
				int till = up.query(1, 1, (int)xVal.size() - 1, x[i]);
				cout << yVal[y[i]] - yVal[till] << '\n';
				lft.modify(1, 1, (int)yVal.size() - 1, till, y[i], x[i]);
			} else {
				int till = lft.query(1, 1, (int)yVal.size() - 1, y[i]);
				cout << xVal[x[i]] - xVal[till] << '\n';
				up.modify(1, 1, (int)xVal.size() - 1, till, x[i], y[i]);
			}
		}
	}
}


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

const int MAXN = 2E5 + 10;

int x[MAXN], y[MAXN];
char dir[MAXN];

struct SegTree {
	int st[MAXN * 4];
	void modify(int id, int l, int r, int qL, int qR, int val) {
		if (qL <= l && r <= qR) {
			st[id] = max(st[id], val);
		} else {
			int m = (l + r) >> 1;
			if (qL <= m) modify(id << 1, l, m, qL, qR, val);
			if (m < qR) modify(id << 1 | 1, m + 1, r, qL, qR, val);
		}
	}
	int query(int id, int l, int r, int p) {
		if (l == r) {
			return st[id];
		} else {
			int m = (l + r) >> 1;
			if (p <= m) return max(st[id], query(id << 1, l, m, p));
			else return max(st[id], query(id << 1 | 1, m + 1, r, p));
		}
	}
} up, lft;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, q; cin >> n >> q;
	vector<int> xVal = { 0 }, yVal = { 0 };
	for (int i = 0; i < q; i++) {
		cin >> x[i] >> y[i] >> dir[i];
		xVal.push_back(x[i]), yVal.push_back(y[i]);
	}
	sort(xVal.begin(), xVal.end()), sort(yVal.begin(), yVal.end());
	xVal.resize(unique(xVal.begin(), xVal.end()) - xVal.begin());
	yVal.resize(unique(yVal.begin(), yVal.end()) - yVal.begin());
	for (int i = 0; i < q; i++) {
		x[i] = (int)(lower_bound(xVal.begin(), xVal.end(), x[i]) - xVal.begin());
		y[i] = (int)(lower_bound(yVal.begin(), yVal.end(), y[i]) - yVal.begin());
	}
	for (int i = 0; i < q; i++) {
		if (dir[i] == 'U') {
			int till = up.query(1, 1, q + 1, x[i]);
			cout << yVal[y[i]] - yVal[till] << '\n';
			lft.modify(1, 1, q + 1, till, y[i], x[i]);
		} else {
			int till = lft.query(1, 1, q + 1, y[i]);
			cout << xVal[x[i]] - xVal[till] << '\n';
			up.modify(1, 1, q + 1, till, x[i], y[i]);
		}
	}
}


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

const int MAXN = 2E5 + 10;

int x[MAXN], y[MAXN];
char dir[MAXN];

struct SegTree {
	int st[MAXN * 4];
	void modify(int id, int l, int r, int qL, int qR, int val) {
		if (qL <= l && r <= qR) {
			st[id] = max(st[id], val);
		} else {
			int m = (l + r) >> 1;
			if (qL <= m) modify(id << 1, l, m, qL, qR, val);
			if (m < qR) modify(id << 1 | 1, m + 1, r, qL, qR, val);
		}
	}
	int query(int id, int l, int r, int p) {
		if (l == r) {
			return st[id];
		} else {
			int m = (l + r) >> 1;
			if (p <= m) return max(st[id], query(id << 1, l, m, p));
			else return max(st[id], query(id << 1 | 1, m + 1, r, p));
		}
	}
} up, lft;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, q; cin >> n >> q;
	vector<int> xVal = { 0 }, yVal = { 0 };
	for (int i = 0; i < q; i++) {
		cin >> x[i] >> y[i] >> dir[i];
		xVal.push_back(x[i]), yVal.push_back(y[i]);
	}
	sort(xVal.begin(), xVal.end()), sort(yVal.begin(), yVal.end());
	xVal.resize(unique(xVal.begin(), xVal.end()) - xVal.begin());
	yVal.resize(unique(yVal.begin(), yVal.end()) - yVal.begin());
	for (int i = 0; i < q; i++) {
		x[i] = (int)(lower_bound(xVal.begin(), xVal.end(), x[i]) - xVal.begin());
		y[i] = (int)(lower_bound(yVal.begin(), yVal.end(), y[i]) - yVal.begin());
	}
	for (int i = 0; i < q; i++) {
		if (dir[i] == 'U') {
			int till = up.query(1, 1, n, x[i]);
			cout << yVal[y[i]] - yVal[till] << '\n';
			lft.modify(1, 1, q, till, y[i], x[i]);
		} else {
			int till = lft.query(1, 1, n, y[i]);
			cout << xVal[x[i]] - xVal[till] << '\n';
			up.modify(1, 1, q, till, x[i], y[i]);
		}
	}
}


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

const int MAXN = 2E5 + 10;

int x[MAXN], y[MAXN];
char dir[MAXN];

struct SegTree {
	int st[MAXN * 4];
	void modify(int id, int l, int r, int qL, int qR, int val) {
		if (qL <= l && r <= qR) {
			st[id] = max(st[id], val);
		} else {
			int m = (l + r) >> 1;
			if (qL <= m) modify(id << 1, l, m, qL, qR, val);
			if (m < qR) modify(id << 1 | 1, m + 1, r, qL, qR, val);
		}
	}
	int query(int id, int l, int r, int p) {
		if (l == r) {
			return st[id];
		} else {
			int m = (l + r) >> 1;
			if (p <= m) return max(st[id], query(id << 1, l, m, p));
			else return max(st[id], query(id << 1 | 1, m + 1, r, p));
		}
	}
} up, lft;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, q; cin >> n >> q;
	vector<int> xVal = { 0 }, yVal = { 0 };
	for (int i = 0; i < q; i++) {
		cin >> x[i] >> y[i] >> dir[i];
		xVal.push_back(x[i]), yVal.push_back(y[i]);
	}
	sort(xVal.begin(), xVal.end()), sort(yVal.begin(), yVal.end());
	xVal.resize(unique(xVal.begin(), xVal.end()) - xVal.begin());
	yVal.resize(unique(yVal.begin(), yVal.end()) - yVal.begin());
	for (int i = 0; i < q; i++) {
		x[i] = (int)(lower_bound(xVal.begin(), xVal.end(), x[i]) - xVal.begin());
		y[i] = (int)(lower_bound(yVal.begin(), yVal.end(), y[i]) - yVal.begin());
	}
	for (int i = 0; i < q; i++) {
		if (dir[i] == 'U') {
			int till = up.query(1, 1, (int)xVal.size() - 1, x[i]);
			cout << yVal[y[i]] - yVal[till] << '\n';
			lft.modify(1, 1, (int)yVal.size() - 1, till, y[i], x[i]);
		} else {
			int till = lft.query(1, 1, (int)yVal.size() - 1, y[i]);
			cout << xVal[x[i]] - xVal[till] << '\n';
			up.modify(1, 1, (int)xVal.size() - 1, till, x[i], y[i]);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
// #define int long long
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define pii pair<ll,int>
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){
    uniform_int_distribution<ll> uid(l, r);
    return uid(rng);
}

const int mod = 1e9 + 7;
int pwr(int a,int b) {
	if(b == -1) return pwr(a, mod - 2);
    int ans = 1;
    while(b) {
        if(b & 1) {
            ans = (ans * 1LL * a) % mod;
        }
        a = (a * 1LL * a) % mod;
        b >>= 1;
    }
    return ans;
}

map<pii,pii> m;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, q;
    cin >> n >> q;
    m[{1, n}] = {0, 0};
    fr(i, 1, q) {
    	int x, y;
    	char ch;
    	cin >> x >> y >> ch;
    	auto it = m.upper_bound({x, 2e9});
    	if(it == m.begin()) {
    		cout << 0 << endl;
    		continue;
    	}
    	it--;
    	pii p1 = it -> fi;
    	pii p2 = it -> se;
    	if(p1.fi <= x && x <= p1.se) {
    		m.erase(it);
    		if(ch == 'U') {
    			int val = p2.fi + p1.se - x + 1;
    			cout << val << endl;
    			if(p1.fi < x)
    				m[{p1.fi, x - 1}] = {val, p2.se};
    			if(x < p1.se)
    				m[{x + 1, p1.se}] = {p2.fi, 0};
    		}
    		else {
    			int val = p2.se + x - p1.fi + 1;
    			cout << val << endl;
    			if(p1.fi < x)
    				m[{p1.fi, x - 1}] = {0, p2.se};
    			if(x < p1.se)
    				m[{x + 1, p1.se}] = {p2.fi, val};
    		}
    	}
    	else {
    		cout << 0 << endl;
    	}
    	// for(auto x : m) {
    	// 	// cout << x.fi.fi << " " << x.fi.se << endl;
    	// 	// cout << x.se.fi << " " << x.se.se << endl;
    	// }
    	// cout << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define fi first
#define se second
#define md 1000000007
#define gc getchar
#define filein freopen("inputf.txt","r",stdin)
#define fileout freopen("outputf.txt","w",stdout)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define br printf("\n");
#define PI 3.14159265359
#define pss printf
#define s_clk clock_t clk = clock()
#define e_clk cout<<(float)(clock()-clk)/CLOCKS_PER_SEC

typedef long long int ll;
typedef long double ld;
typedef priority_queue<int,vector<int>,greater<int> > spq; // min priority queue
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> o_set;
#define int long long int

struct ppair{
int fi,se;
ppair(int a,int b):fi(a),se(b){}
ppair():fi(0),se(0){}
};
inline bool cmp(const ppair &a,const ppair &b)
{
if(a.fi==b.fi)
	return a.se<b.se;
return a.fi<b.fi;
}

int pmod(int a, int m){
return (a%m + m)%m;
}
void sscan(string &s, const int MAX){
char a[MAX];
scanf("%s",a);
s = string(a);
}
int stringtoint(string s){
stringstream c(s);
int x = 0;
c>>x;
return x;}

template<typename T> T power(T a,T b,T m)
{
T ans = 1,p = a;
while(b)
{
	if(b&1)
		ans = (ans*p)%m;
	p = (p*p)%m;
	b>>=1;
}
return ans;
}

template<typename T> T gcd(T a,T b)
{
if(b==0)
	return a;
else
	return gcd(b,a%b);
}
template<typename T> T e_gcd(T a,T b,T &x,T &y)
{
if(b==0)
{
	x = 1,y = 0;
	return a;
}
T x1,y1;
T g = e_gcd(b,a%b,x1,y1);
x = y1;
y = x1-(a/b)*y1;
if(y<0)
{
	y+=a;
	x-=b;
}
return g;
}
template<typename T> T invmod(T a,T m)
{
T x,y,g;
g = e_gcd(m,a,x,y);
if(g!=1)
	return -1;
else
	return y;
}

inline void sc(int &x)
{
register int c = gc();
bool flag = false;
x = 0;
for(;((c<48 && c!=45) || c>57);c = gc());
if(c==45)
{
flag = true;
c = gc();
}
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
if(flag)
x = x - (x<<1);
return;
}
inline void scll(ll &x)
{
register int c = gc();
bool flag = false;
x = 0;
for(;((c<48 && c!=45) || c>57);c = gc());
if(c==45)
{
flag = true;
c = gc();
}
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
if(flag)
x = x - (x<<1);
return;
}
inline bool cmp1(const pair<pair<int,int>,int> &p1, const pair<pair<int,int>,int> &p2)
{
	return p1.se>p2.se;
}
typedef pair<pair<int,int>,int> pii;
class Compare
{
public:
    bool operator() (const pii &a, const pii &b)
    {
        return a.se<b.se;
    }
};
const int N = 100005;
vector<int> a[N];
signed main()
{
//filein;
int n,k;
slld(n);slld(k);
int ans = 0;
int ind;
for(int i=1;i<=k;i++)
{
	int m;
	slld(m);
	ans+=(m-1);
	a[i].pb(m);
	for(int j=1;j<=m;j++)
	{
		int x;
		slld(x);
		if(x==1)
		{
			ind = i;
			ans-=(m-1);
		}
		a[i].pb(x);
	}
}
int cnt = 1;
for(int i=1;i<a[ind][0];i++)
{
	if(a[ind][i+1]==a[ind][i]+1)
		cnt++;
	else
		break;
}
ans+=(n-cnt);
ans+=(a[ind][0]-cnt);
plld(ans);
return 0;
}


#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int n,q,ans;
const int maxn=200500;
int t[2][maxn*30],lc[2][maxn*30],rc[2][maxn*30];
int tot[2],rt[2];
void up(int op,int x){
    int l=lc[op][x],r=rc[op][x];
    if (l) t[op][x]=max(t[op][x],t[op][l]);
    if (r) t[op][x]=max(t[op][x],t[op][r]);
}
void down(int op,int x){
    int &l=lc[op][x],&r=rc[op][x];
    if (!l) l=++tot[op];
    if (!r) r=++tot[op];
    t[op][l]=max(t[op][l],t[op][x]);
    t[op][r]=max(t[op][r],t[op][x]);
}
void ask(int &x,int l,int r,int pos,int op){
    if (!x) x=++tot[op];
    ans=max(ans,t[op][x]);
    if (l==r) return;
    int mid=(l+r)>>1;
    if (pos<=mid) ask(lc[op][x],l,mid,pos,op);
    else ask(rc[op][x],mid+1,r,pos,op);
}
void cg(int &x,int l,int r,int L,int R,int val,int op){
    if (!x) x=++tot[op];
    if (L<=l&&r<=R) {t[op][x]=max(t[op][x],val); return;}
    int mid=(l+r)>>1;
    if (L<=mid) cg(lc[op][x],l,mid,L,R,val,op);
    if (R>mid) cg(rc[op][x],mid+1,r,L,R,val,op);
}
unordered_map<int,int> mp;
int main(){
//    freopen("in.txt","r",stdin);
    scanf("%d%d\n",&n,&q);
    rep(i,1,q){
        int x,y; char c;
        scanf("%d %d %c",&x,&y,&c);
        if (mp.count(x)) {puts("0"); continue;}
        mp[x]=1;
        if (c=='U') {
            ans=0;
            ask(rt[0],1,n,y,0);
            cg(rt[1],1,n,n+1-y,n-ans,x,1);
            printf("%d\n",y-ans);
        }
        else {
            ans=0;
            ask(rt[1],1,n,x,1);
            cg(rt[0],1,n,n+1-x,n-ans,y,0);
            printf("%d\n",x-ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int n,q,ans;
const int maxn=200500;
int t[2][maxn*30],lc[2][maxn*30],rc[2][maxn*30];
int tot[2],rt[2];
void ask(int &x,int l,int r,int L,int R,int op){
    if (!x) x=++tot[op];
    ans=max(ans,t[op][x]);
    if (l==r) return;
    int mid=(l+r)>>1;
    if (L<=mid) ask(lc[op][x],l,mid,L,R,op);
    if (R>mid) ask(rc[op][x],mid+1,r,L,R,op);
}
void cg(int &x,int l,int r,int L,int R,int val,int op){
    if (!x) x=++tot[op];
    if (L<=l&&r<=R) t[op][x]=max(t[op][x],val);
    if (l==r) return;
    int mid=(l+r)>>1;
    if (L<=mid) cg(lc[op][x],l,mid,L,R,val,op);
    if (R>mid) cg(rc[op][x],mid+1,r,L,R,val,op);
}
unordered_map<int,int> mp;
int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d%d\n",&n,&q);
    rep(i,1,q){
        int x,y; char c;
        scanf("%d %d %c\n",&x,&y,&c);
        if (mp.count(x)) {puts("0"); continue;}
        mp[x]=1;
        if (c=='U') {
            ans=0;
            ask(rt[0],1,n,1,y,0);
            cg(rt[1],1,n,n+1-y,n-ans,x,1);
            printf("%d\n",y-ans);
        }
        else {
            ans=0;
            ask(rt[1],1,n,1,x,1);
            cg(rt[0],1,n,n+1-x,n-ans,y,0);
            printf("%d\n",x-ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int n,q,ans;
const int maxn=200500;
int t[2][maxn*30],lc[2][maxn*30],rc[2][maxn*30];
int tot[2],rt[2];
void ask(int &x,int l,int r,int L,int R,int op){
    if (!x) return;
    ans=max(ans,t[op][x]);
    if (l==r) return;
    int mid=(l+r)>>1;
    if (L<=mid) ask(lc[op][x],l,mid,L,R,op);
    if (R>mid) ask(rc[op][x],mid+1,r,L,R,op);
}
void cg(int &x,int l,int r,int L,int R,int val,int op){
    if (!x) x=++tot[op];
    if (L<=l&&r<=R) {t[op][x]=max(t[op][x],val); return;}
    int mid=(l+r)>>1;
    if (L<=mid) cg(lc[op][x],l,mid,L,R,val,op);
    if (R>mid) cg(rc[op][x],mid+1,r,L,R,val,op);
}
unordered_map<int,int> mp;
int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d%d\n",&n,&q);
    rep(i,1,q){
        int x,y; char c;
        scanf("%d %d %c",&x,&y,&c);
        if (mp.count(x)) {puts("0"); continue;}
        mp[x]=1;
        if (c=='U') {
            ans=0;
            ask(rt[0],1,n,1,y,0);
            cg(rt[1],1,n,n+1-y,n-ans,x,1);
            printf("%d\n",y-ans);
        }
        else {
            ans=0;
            ask(rt[1],1,n,1,x,1);
            cg(rt[0],1,n,n+1-x,n-ans,y,0);
            printf("%d\n",x-ans);
        }
    }
    return 0;
}


import static java.lang.Math.*;

public class C {

	public C () {
		long N = sc.nextInt();
		int Q = sc.nextInt();

		MaxNode H = new MaxNode(-1, N+1);
		MaxNode V = new MaxNode(-1, N+1);

		for (int q : rep(Q)) {
			long x = sc.nextInt(), y = sc.nextInt();
			char d = sc.nextChar();

			if (d == 'U') {
				long h = H.get(x);
				long res = y - h;
				print(res);

				if (res > 0)
					V.add(x, h+1, y+1);
			}

			if (d == 'L') {
				long v = V.get(y);
				long res = x - v;
				print(res);

				if (res > 0)
					H.add(y, v+1, x+1);
			}
		}
	}

	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static class MaxNode {
		private MaxNode L, R;
		private final long from, to, m;
		private long X = 0;
		public void add(long X, long from, long to) {
			assert(from >= this.from && to <= this.to && from < to);
			if (from == this.from && to == this.to)
				this.X = max(this.X, X);
			else {
				if (from < m) {
					if (L == null)
						L = new MaxNode(this.from, m);
					L.add(X, from, min(to, m));
				}
				if (to > m) {
					if (R == null)
						R = new MaxNode(m, this.to);
					R.add(X, max(from, m), to);
				}
			}
		}
		private long get(long i) {
			assert(from <= i && i < to);
			long res = X;
			if (i < m && L != null)
				res = max(res, L.get(i));
			if (i >= m && m > from && R != null)
				res = max(res, R.get(i));
			return res;
		}
		private MaxNode(long from, long to) {
			assert(from < to);
			this.from = from;
			this.to = to;
			m = (from + to) / 2;
			//			if (m > from) {
			//				L = new MaxNode(from, m);
			//				R = new MaxNode(m, to);
			//			} else
			//				L = R = null;
		}
	}
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void print (Object o, Object ... A) { IOUtils.print(o, A); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public char nextChar() { return next().charAt(0); }
			public int nextInt() { return Integer.parseInt(next()); }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new C(); IOUtils.exit(); }
}


import java.util.*;

public class C {

	public C () {
		int N = sc.nextInt();
		int Q = sc.nextInt();

		int [] ZERO = { 0, 0 };
		TreeMap<Integer, int[]> X = new TreeMap<>();
		X.put(-1, ZERO); X.put(N+1, ZERO);

		for (int q : rep(Q)) {
			int x = sc.nextInt(), y = sc.nextInt();
			char d = sc.nextChar();

			if (X.containsKey(x))
				print(0);

			else {
				if (d == 'U') {
					int [] v = X.ceilingEntry(x).getValue();
					print(y - v[1]);
					X.put(x, new int [] { x, v[1] });
				}

				if (d == 'L') {
					int [] v = X.floorEntry(x).getValue();
					print(x - v[0]);
					X.put(x, new int [] { v[0], y });
				}
			}
		}
	}

	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void print (Object o, Object ... A) { IOUtils.print(o, A); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public char nextChar() { return next().charAt(0); }
			public int nextInt() { return Integer.parseInt(next()); }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new C(); IOUtils.exit(); }
}


import static java.lang.Math.*;

import java.util.*;

public class C {

	public C () {
		int N = sc.nextInt();
		int Q = sc.nextInt();

		MaxNode H = new MaxNode(-1, N+1);
		MaxNode V = new MaxNode(-1, N+1);

		Set<Integer> XX = new TreeSet<>();

		for (int q : rep(Q)) {
			int x = sc.nextInt(), y = sc.nextInt();
			char d = sc.nextChar();

			if (XX.add(x)) {
				if (d == 'U') {
					int h = H.get(x);
					int res = y - h;
					print(res);

					if (res > 0)
						V.add(x, h+1, y+1);
				}

				if (d == 'L') {
					int v = V.get(y);
					int res = x - v;
					print(res);

					if (res > 0)
						H.add(y, v+1, x+1);
				}
			}
			else
				print(0);
		}
	}

	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static class MaxNode {
		private MaxNode L, R;
		private final int from, to, m;
		private int X = 0;
		public void add(int X, int from, int to) {
			assert(from >= this.from && to <= this.to && from < to);
			if (from == this.from && to == this.to)
				this.X = max(this.X, X);
			else {
				if (from < m) {
					if (L == null)
						L = new MaxNode(this.from, m);
					L.add(X, from, min(to, m));
				}
				if (to > m) {
					if (R == null)
						R = new MaxNode(m, this.to);
					R.add(X, max(from, m), to);
				}
			}
		}
		private int get(int i) {
			assert(from <= i && i < to);
			int res = X;
			if (i < m && L != null)
				res = max(res, L.get(i));
			if (i >= m && m > from && R != null)
				res = max(res, R.get(i));
			return res;
		}
		private MaxNode(int from, int to) {
			assert(from < to);
			this.from = from;
			this.to = to;
			m = (from + to) / 2;
		}
	}
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void print (Object o, Object ... A) { IOUtils.print(o, A); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public char nextChar() { return next().charAt(0); }
			public int nextInt() { return Integer.parseInt(next()); }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new C(); IOUtils.exit(); }
}


import static java.lang.Math.*;

import java.util.*;

public class C {

	public C () {
		long N = sc.nextInt();
		int Q = sc.nextInt();

		MaxNode H = new MaxNode(-1, N+1);
		MaxNode V = new MaxNode(-1, N+1);

		Set<Long> XX = new TreeSet<>();

		for (int q : rep(Q)) {
			long x = sc.nextInt(), y = sc.nextInt();
			char d = sc.nextChar();

			if (XX.add(x)) {
				if (d == 'U') {
					long h = H.get(x);
					long res = y - h;
					print(res);

					if (res > 0)
						V.add(x, h+1, y+1);
				}

				if (d == 'L') {
					long v = V.get(y);
					long res = x - v;
					print(res);

					if (res > 0)
						H.add(y, v+1, x+1);
				}
			}
			else
				print(0);
		}
	}

	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static class MaxNode {
		private MaxNode L, R;
		private final long from, to, m;
		private long X = 0;
		public void add(long X, long from, long to) {
			assert(from >= this.from && to <= this.to && from < to);
			if (from == this.from && to == this.to)
				this.X = max(this.X, X);
			else {
				if (from < m) {
					if (L == null)
						L = new MaxNode(this.from, m);
					L.add(X, from, min(to, m));
				}
				if (to > m) {
					if (R == null)
						R = new MaxNode(m, this.to);
					R.add(X, max(from, m), to);
				}
			}
		}
		private long get(long i) {
			assert(from <= i && i < to);
			long res = X;
			if (i < m && L != null)
				res = max(res, L.get(i));
			if (i >= m && m > from && R != null)
				res = max(res, R.get(i));
			return res;
		}
		private MaxNode(long from, long to) {
			assert(from < to);
			this.from = from;
			this.to = to;
			m = (from + to) / 2;
			//			if (m > from) {
			//				L = new MaxNode(from, m);
			//				R = new MaxNode(m, to);
			//			} else
			//				L = R = null;
		}
	}
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void print (Object o, Object ... A) { IOUtils.print(o, A); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public char nextChar() { return next().charAt(0); }
			public int nextInt() { return Integer.parseInt(next()); }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new C(); IOUtils.exit(); }
}


import java.util.*;
public final class Chocolate
{
	public static void main(String arg[])
	{
	Scanner br=new Scanner(System.in);
	int n=br.nextInt();
	int q=br.nextInt();
	int x[]=new int[200005];
	int y[]=new int[200005];
	ArrayList<Integer> g=new ArrayList<Integer>();
	int j=0;
	x[0]=y[0]=0;
	x[q+1]=y[q+1]=0;
	TreeMap<Integer ,Integer > t=new TreeMap<Integer ,Integer >();
	t.put(0,q+1);
	t.put(n+1,q+1);
	//Iterator<Pair> it=t.iterator();
	Map.Entry<Integer ,Integer> it;

	for(int i=1;i<=q;i++)
	{
x[i]=br.nextInt();
y[i]=br.nextInt();
//br.nextLine();
String s=new String(br.next());
if(s.charAt(0)=='U')
{
	 it=t.ceilingEntry(x[i]);

}
else
{
	 it=t.floorEntry(x[i]);

}

if(it.getKey()==x[i])
{
	g.add(0);
	continue;
}
t.put(x[i],i);
if(s.charAt(0)=='U')
{
g.add(y[i]-y[it.getValue()]);
	y[i]=y[it.getValue()];
}
else{
	g.add(x[i]-x[it.getValue()]);
	x[i]=x[it.getValue()];
}

	}
	Iterator<Integer> itr=g.iterator();
	while(itr.hasNext())
		System.out.print(itr.next()+"	");
	}

}

final class MyEntry<K, V> implements Map.Entry<K, V> {
    private final K key;
    private V value;

    public MyEntry(K key, V value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return value;
    }

    @Override
    public V setValue(V value) {
        V old = this.value;
        this.value = value;
        return old;
    }
}


import java.util.*;
public final class Chocolate
{
	public static void main(String arg[])
	{
	Scanner br=new Scanner(System.in);
	int n=br.nextInt();
	int q=br.nextInt();
	int x[]=new int[200005];
	int y[]=new int[200005];
	ArrayList<Integer> g=new ArrayList<Integer>();
	int j=0;
	x[0]=y[0]=0;
	x[q+1]=y[q+1]=0;
	TreeMap<Integer ,Integer > t=new TreeMap<Integer ,Integer >();
	t.put(0,q+1);
	t.put(n+1,q+1);a

	Map.Entry<Integer ,Integer> it;

	for(int i=1;i<=q;i++)
	{
x[i]=br.nextInt();
y[i]=br.nextInt();
//br.nextLine();
String s=new String(br.next());
if(s.charAt(0)=='U')
{
	 it=t.higherEntry(x[i]);

}
else
{
	 it=t.floorEntry(x[i]);

}
t.put(x[i],i);
if(it.getKey()==x[i])
{
	g.add(0);
	continue;
}
if(s.charAt(0)=='U')
{
g.add(y[i]-y[it.getValue()]);
	y[i]=y[it.getValue()];
}
else{
	g.add(x[i]-x[it.getValue()]);
	x[i]=x[it.getValue()];
}

	}
	Iterator<Integer> itr=g.iterator();
	while(itr.hasNext())
		System.out.print(itr.next()+"  ");
	}

}

final class MyEntry<K, V> implements Map.Entry<K, V> {
    private final K key;
    private V value;

    public MyEntry(K key, V value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return value;
    }

    @Override
    public V setValue(V value) {
        V old = this.value;
        this.value = value;
        return old;
    }
}


import java.io.*;
import java.util.*;

public class CF {
	FastScanner in;
	PrintWriter out;

	class Segment implements Comparable<Segment> {
		int from, to, value;

		public Segment(int from, int to, int value) {
			super();
			this.from = from;
			this.to = to;
			this.value = value;
		}

		@Override
		public int compareTo(Segment o) {
			if (from == o.from) {
				return Integer.compare(to, o.to);
			}
			return Integer.compare(from, o.from);
		}

		@Override
		public String toString() {
			return "Segment [from=" + from + ", to=" + to + ", value=" + value
					+ "]";
		}

	}

	void addSegment(TreeSet<Segment> segments, Segment cur) {
		while (true) {
			Segment tmp = segments.lower(new Segment(cur.to, Integer.MAX_VALUE,
					0));
			if (tmp == null) {
				segments.add(cur);
				break;
			}
			if (tmp.value >= cur.value) {
				if (tmp.to < cur.to) {
					segments.add(new Segment(tmp.to + 1, cur.to, cur.value));
				}
				return;
			}
			if (tmp.to < cur.from) {
				segments.add(cur);
				break;
			}
			segments.remove(tmp);
			if (tmp.to > cur.to) {
				segments.add(new Segment(cur.to + 1, tmp.to, tmp.value));
			}
			if (tmp.from < cur.from) {
				segments.add(new Segment(tmp.from, cur.from - 1, tmp.value));
			}
		}
	}

	class Pair {
		int x, y;

		public Pair(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + x;
			result = prime * result + y;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (x != other.x)
				return false;
			if (y != other.y)
				return false;
			return true;
		}

		private CF getOuterType() {
			return CF.this;
		}

	}

	void solve() {
		int n = in.nextInt();
		int q = in.nextInt();
		TreeSet<Segment> ySegm = new TreeSet<>();
		ySegm.add(new Segment(1, n, 0));
		TreeSet<Segment> xSegm = new TreeSet<>();
		xSegm.add(new Segment(1, n, 0));
		HashSet<Pair> allPairs = new HashSet<>();
		for (int i = 0; i < q; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			String dir = in.next();
			boolean goesUp = dir.charAt(0) == 'U';
			Pair now = new Pair(x, y);
			if (allPairs.contains(now)) {
				out.println(0);
				continue;
			}
			allPairs.add(now);
			if (goesUp) {
				Segment seg = ySegm.lower(new Segment(x, Integer.MAX_VALUE, 0));
				int curLen = y - seg.value;
				out.println(curLen);
				if (curLen != 0) {
					addSegment(xSegm, new Segment(y - curLen + 1, y, x));
				}
			} else {
				Segment seg = xSegm.lower(new Segment(y, Integer.MAX_VALUE, 0));
				int curLen = x - seg.value;
				out.println(curLen);
				if (curLen != 0) {
					addSegment(ySegm, new Segment(x - curLen + 1, x, y));
				}
			}
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	void run() {
		try {
			in = new FastScanner(new File("test.in"));
			out = new PrintWriter(new File("test.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new CF().runIO();
	}
}


import java.io.*;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args){
		new TaskC().solve();
	}

}

class TaskC {

	public void solve() {
		Scanner in=new Scanner(new BufferedInputStream(System.in));

		long n=in.nextLong();
		int q=in.nextInt();
		long[] x=new long[q];
		long[] y=new long[q];
		String str;
		TreeSet<Integer> ts=new TreeSet<Integer>();
		TreeSet<Pair> us=new TreeSet<Pair>();
		for(int i=0;i<q;i++) {
			x[i]=in.nextLong();
			y[i]=in.nextLong();
			str=in.next();
			if(ts.contains(x[i])){
				System.out.println(0);
				continue;
			}
			us.add(new Pair(x[i],i));
			if(str.equals("U")){
				Pair p=us.higher(new Pair(x[i],i));
				if(p==null){
					System.out.println(y[i]);
					y[i]=0;
				}
				else{
					System.out.println(y[i]-y[p.id]);
					y[i]=y[p.id];
				}
			}
			else {
				Pair p=us.lower(new Pair(x[i],i));
				if(p==null){
					System.out.println(x[i]);
					x[i]=0;
				}
				else{
					System.out.println(x[i]-x[p.id]);
					x[i]=x[p.id];
				}
			}
		}
	}

	class Pair implements Comparable<Pair> {
		long col;
		int id;

		public Pair(long col,int id) {
			this.col=col;
			this.id=id;
		}

		@Override
		public int compareTo(Pair o) {
			int z=Long.compare(col,o.col);
			if(z==0){
				z=Long.compare(id,o.id);
			}
			return z;
		}

	}
}


#include <bits/stdc++.h>

using namespace std;
int l,r,mid,n,t,i,t2,m;
string s,pp,ss,kq;
bool kt(int k)
{
    t=0;i=0;ss=pp;
    while (i<n)
    {
       if (s[i]=='(' && t<k) {ss[i]='1';t++;} else if (s[i]==')' && t>0) {ss[i]='1';t--;}
      i++;

    }

    t2=0;i=0;m=0;
    while (i<n)
    {
        if (ss[i]=='0' )
        {
            if (s[i]=='(')t2++;else t2--;
        }
        m=max(m,t2);
            i++;
    }
    if (m<=k) {kq=ss;return 1;}
    return 0;
}
int main()
{   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;for (i=1;i<=n;i++) pp+='0';
    cin>>s;
    l=1;r=400000;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (kt(mid)) r=mid-1; else l=mid+1;
    }
    cout<<kq;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int l,r,mid,n,t,i,t2,m;
string s,pp,ss,kq;
bool kt(int k)
{
    t=0;i=0;ss=pp;
    while (t<=k && i<n)
    {
       if (s[i]=='(') {ss[i]='1';t++;}i++;
    }
    while (t>0 && i<n)
    {
        if (s[i]==')') {ss[i]='1';t--;}i++;
    }
    t2=0;i=0;m=0;
    while (i<n)
    {
        if (ss[i]=='0' )
        {
            if (s[i]=='(')t2++;else t2--;
        }
        m=max(m,t2);
            i++;
    }
    if (m<=k) {kq=ss;return 1;}
    return 0;
}
int main()
{   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;for (i=1;i<=n;i++) pp+='0';
    cin>>s;
    l=0;r=200000;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (kt(mid)) r=mid-1; else l=mid+1;
    }
    cout<<kq;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int l,r,mid,n,t,i,t2,m;
string s,pp,ss,kq;
bool kt(int k)
{
    t=0;i=0;ss=pp;
    while (i<n)
    {
       if (s[i]=='(' && t<k) {ss[i]='1';t++;} else if (s[i]==')' && t>0) {ss[i]='1';t--;}
       else i++;

    }

    t2=0;i=0;m=0;
    while (i<n)
    {
        if (ss[i]=='0' )
        {
            if (s[i]=='(')t2++;else t2--;
        }
        m=max(m,t2);
            i++;
    }
    if (m<=k) {kq=ss;return 1;}
    return 0;
}
int main()
{   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;for (i=1;i<=n;i++) pp+='0';
    cin>>s;
    l=0;r=200000;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (kt(mid)) r=mid-1; else l=mid+1;
    }
    cout<<kq;
    return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<n;i++){
       int left=0;
       int right=0;
       int j;
       int count=0;
       int ans=0;
       for(j=i;j<n;j++){
           if(a[j]=='('){
               left++;
               count++;
           }else if(a[j]==')'){
               right++;
               ans=max(ans,count);
               count--;
           }
           if(left==right && left>0){
               break;
           }
       }
       count=ans;
       int t;
       if(count%2){
           t=(count/2) + 1;
       }else{
           t=count/2;
       }
       int x=0;
       int x1=0;
       int k=j;
       for(j=i;j<=k;j++){
           if(a[j]=='('){
               if(t>x){
                   b[j]=0;
                   x++;
               }else{
                   b[j]=1;
               }
           }else{
               if(t>x1){
                   b[j]=0;
                   x1++;
               }else{
                   b[j]=1;
               }
           }
       }
       i=k;
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<n;i++){
       int left=0;
       int right=0;
       int j;
       int count=0;
       int ans=0;
       for(j=i;j<n;j++){
           if(a[j]=='('){
               left++;
               count++;
           }else if(a[j]==')'){
               right++;
               ans=max(ans,count);
               count--;
           }
           if(left==right && left>0){
               break;
           }
       }
       count=ans;
       int t=count/2;
       int x=0;
       int x1=0;
       int k=j;
       for(j=i;j<=k;j++){
           if(a[j]=='('){
               if(t>=x){
                   b[j]=0;
                   x++;
               }else{
                   b[j]=1;
               }
           }else{
               if(t>=x1){
                   b[j]=0;
                   x1++;
               }else{
                   b[j]=1;
               }
           }
       }
       i=k;
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   std::stack<char>s ;
   vector<pair<int,int>>v;
   int count=0;
   int k=0;
   for(int i=0;i<n;i++){
       if(s.empty()){
           if(count){
               v.pb(mp(count,k));
           }
           k=i;
           count=0;
           count++;
           s.push(a[i]);
       }else{
           if(a[i]=='('){
               count++;
               s.push(a[i]);
           }else{
               count++;
               s.pop();
           }
       }
   }
   if(count){
       v.pb(mp(count,k));
   }
   count=0;
   k=0;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<v.size();i++){
       count=v[i].F;
       int t=count/2;
       t/=2;
       int x=0;
       int x1=0;
       for(int j=v[i].S;j<(v[i].S+v[i].F);j++){
           if(v[i].F>2){
               if(a[j]=='('){
                   if(t>x){
                       b[j]=0;
                       x++;
                   }else{
                       b[j]=1;
                   }
               }else{
                   if(t>x1){
                       b[j]=0;
                       x1++;
                   }else{
                       b[j]=1;
                   }
               }
           }else{
               b[j]=0;
           }
       }
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   std::stack<char>s ;
   vector<pair<int,int>>v;
   int count=0;
   int k=0;
   for(int i=0;i<n;i++){
       if(s.empty()){
           if(count){
               v.pb(mp(count,k));
           }
           k=i;
           count=0;
           count++;
           s.push(a[i]);
       }else{
           if(a[i]=='('){
               count++;
               s.push(a[i]);
           }else{
               count++;
               s.pop();
           }
       }
   }
   if(count){
       v.pb(mp(count,k));
   }
   count=0;
   k=0;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<v.size();i++){
       count=v[i].F;
       int t=count/2;
       t/=2;
       int x=0;
       int x1=0;
       for(int j=v[i].S;j<(v[i].S+v[i].F);j++){
           if(v[i].F>2){
               if(a[j]=='('){
                   if(t>x){
                       b[j]=1;
                       x++;
                   }else{
                       b[j]=0;
                   }
               }else{
                   if(t>x1){
                       b[j]=1;
                       x1++;
                   }else{
                       b[j]=0;
                   }
               }
           }else{
               b[j]=1;
           }
       }
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<n;i++){
       int left=0;
       int right=0;
       int j;
       int count=0;
       int ans=0;
       for(j=i;j<n;j++){
           if(a[j]=='('){
               left++;
               count++;
           }else if(a[j]==')'){
               right++;
               ans=max(ans,count);
               count--;
           }
           if(left==right && left>0){
               break;
           }
       }
       count=ans;
       if(count%2){
           t=(count/2) + 1;
       }else{
           t=count/2;
       }
       int x=0;
       int x1=0;
       int k=j;
       for(j=i;j<=k;j++){
           if(a[j]=='('){
               if(t>x){
                   b[j]=0;
                   x++;
               }else{
                   b[j]=1;
               }
           }else{
               if(t>x1){
                   b[j]=0;
                   x1++;
               }else{
                   b[j]=1;
               }
           }
       }
       i=k;
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<n;i++){
       int left=0;
       int right=0;
       int j;
       int count=0;
       int ans=0;
       for(j=i;j<n;j++){
           if(a[j]=='('){
               left++;
               count++;
           }else if(a[j]==')'){
               right++;
               ans=max(ans,count);
               count--;
           }
           if(left==right && left>0){
               break;
           }
       }
       count=ans;
       int t;
       if(count%2){
           t=(count/2) + 1;
       }else{
           t=count/2;
       }
       int x=0;
       int x1=0;
       int x2=0;
       int x3=0;
       int k=j;
       for(j=i;j<=k;j++){
           if(a[j]=='('){
               if(t>x){
                   b[j]=0;
                   x++;
               }else if(t>x2){
                   b[j]=1;
                   x2++;
               }
           }else{
               if(t>x1){
                   b[j]=0;
                   x1++;
               }else if(t>x3){
                   b[j]=1;
                   x3++;
               }
           }
           if(t==x && t==x2){
               x=0;
               x2=0;
           }
           if(t==x1 && (t==x3)){
               x1=0;
               x3=0;
           }
       }
       i=k;
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define vi          vector<int>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()

ll power(ll a,ll b){

    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b=b>>1;
    }
    return result%MOD;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> SieveOfEratosthenes(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<int>v;
    v.pb(0);
    for (int p=2; p<=n; p++)
       if (prime[p]) v.pb(p);

    return v;
}

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

   int n;
   cin>>n;
   string a;
   cin>>a;
   int b[n];
   for(int i=0;i<n;i++){
       b[i]=0;
   }
   for(int i=0;i<n;i++){
       int left=0;
       int right=0;
       int j;
       int count=0;
       int ans=0;
       for(j=i;j<n;j++){
           if(a[j]=='('){
               left++;
               count++;
           }else if(a[j]==')'){
               right++;
               ans=max(ans,count);
               count--;
           }
           if(left==right && left>0){
               break;
           }
       }
       count=ans;
       int t=count/2;
       int x=0;
       int x1=0;
       int k=j;
       for(j=i;j<=k;j++){
           if(a[j]=='('){
               if(t>x){
                   b[j]=0;
                   x++;
               }else{
                   b[j]=1;
               }
           }else{
               if(t>x1){
                   b[j]=0;
                   x1++;
               }else{
                   b[j]=1;
               }
           }
       }
       i=k;
   }
   for(int i=0;i<n;i++){
       cout<<b[i];
   }

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define B begin()
#define E end()
#define ld long double
#define ins insert
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define txtin freopen("input.txt","r",stdin)
#define txtout freopen("output.txt","w",stdout)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define Sz size()
#define pub push_back
#define mkp make_pair
#define fr(i,n,m,k) for (int i = (n - 1) ; i >= (m) ; i -= k)
#define fur(i,n,m,k); for (ll i = (n) ; i < (m) ; i+=k)
#define cinfur(i,n,m,k,a) for (ll i = (n) ; i < (m) ; i+=k,cin>>a)
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define p2(n) (1ll<<(n))
#define migmig ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define mxx(mx,a) mx=max(mx,a)
#define mnn(mx,a) mx=min(mx,a)
typedef vector<ll> vll;
typedef map<ll,ll> mll;
const ll N=1e7+5;
ll a[N],sum,mx,n,k,ans;
bool b,b1;
str s;
int main(){
	cin>>n>>s;
	fur(i,0,s.Sz,1){
		if(s[i]=='(')cout<<b,b=1-b;
		else cout <<b1,b1=1-b1;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define B begin()
#define E end()
#define ld long double
#define ins insert
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define txtin freopen("input.txt","r",stdin)
#define txtout freopen("output.txt","w",stdout)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define Sz size()
#define pub push_back
#define mkp make_pair
#define fr(i,n,m,k) for (int i = (n - 1) ; i >= (m) ; i -= k)
#define fur(i,n,m,k); for (ll i = (n) ; i < (m) ; i+=k)
#define cinfur(i,n,m,k,a) for (ll i = (n) ; i < (m) ; i+=k,cin>>a)
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define p2(n) (1ll<<(n))
#define migmig ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define mxx(mx,a) mx=max(mx,a)
#define mnn(mx,a) mx=min(mx,a)
typedef vector<ll> vll;
typedef map<ll,ll> mll;
const ll N=1e7+5;
ll a[N],sum,mx,n,k,ans;
bool b,b1;
str s;
int main(){
	cin>>s;
	fur(i,0,s.Sz,1){
		if(s[i]=='(')cout<<b,b=1-b;
		else cout <<b1,b=1-b;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define B begin()
#define E end()
#define ld long double
#define ins insert
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define txtin freopen("input.txt","r",stdin)
#define txtout freopen("output.txt","w",stdout)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define Sz size()
#define pub push_back
#define mkp make_pair
#define fr(i,n,m,k) for (int i = (n - 1) ; i >= (m) ; i -= k)
#define fur(i,n,m,k); for (ll i = (n) ; i < (m) ; i+=k)
#define cinfur(i,n,m,k,a) for (ll i = (n) ; i < (m) ; i+=k,cin>>a)
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define p2(n) (1ll<<(n))
#define migmig ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define mxx(mx,a) mx=max(mx,a)
#define mnn(mx,a) mx=min(mx,a)
typedef vector<ll> vll;
typedef map<ll,ll> mll;
const ll N=1e7+5;
ll a[N],sum,mx,n,k,ans;
bool b,b1;
str s;
int main(){
	cin>>n>>s;
	fur(i,0,s.Sz,1){
		if(s[i]=='(')cout<<b,b=1-b;
		else cout <<b1,b=1-b;
	}
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r;
set<int> l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);
	reverse(r.begin(), r.end());
	while(!r.empty())
	{
		int now = r.back();
		int x = *l.lower_bound(now);
		ans[now] = 1, ans[x] = 1;
		r.pop_back();
		l.erase(x);
		vector<int> nos ;
		while(!r.empty() && r.back() < x)
		{
			nos.push_back(r.back());
			r.pop_back();
		}
		int cnt = 0;
		for(auto i : nos)
		{
			int fi = i;
			int se = *l.lower_bound(fi);
			l.erase(se);
			if(cnt>=nos.size()/2)
                ans[fi]=ans[se]=1;
            cnt++;
		}
	}
	for(int i = 0; i < n; i++)
		cout << ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r;
set<int> l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);
	reverse(r.begin(), r.end());
	while(!r.empty())
	{
		int now = r.back();
		int x = *l.lower_bound(now);
		ans[now] = 1, ans[x] = 1;
		r.pop_back();
		l.erase(x);
		vector<int> nos ;
		while(!r.empty() && r.back() < x)
		{
			nos.push_back(r.back());
			r.pop_back();
		}
		int cnt = 0;
		for(auto i : nos)
		{
			int fi = i;
			int se = *l.lower_bound(fi);
			l.erase(se);
			if(cnt<nos.size()/2)
                ans[fi]=ans[se]=1;
            cnt++;
		}
	}
	for(int i = 0; i < n; i++)
		cout << ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r;
set<int> l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);
	reverse(r.begin(), r.end());
	while(!r.empty())
	{
		int now = r.back();
		r.pop_back();
		ans[now] = 1;
		int x = *l.lower_bound(now);
		ans[x] = 1;
		l.erase(x);
		int p=x-now-1;
		p/=2;
		while(p--)
        {
            int y=r.back();
            r.pop_back();
            ans[y]=1;
            int xx=*l.lower_bound(y);
            ans[xx]=1;
            l.erase(xx);
        }
		while(!r.empty()&&r.back()<x)
            r.pop_back();
	}
	for(int i=0;i<n;i++)
        cout<<ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009], fi, se;
string s ;
deque<int> r ;
set<int> l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);
	while(!r.empty())
	{
	  //  cout<<5;
		fi = r.front();
		se = *l.lower_bound(fi);
		int extra = lower_bound(r.begin(),r.end(),se-1)-r.begin();
		ans[fi] = ans[se] = 1;
		r.pop_front();
		l.erase(se);
		int nos = extra / 2;
		extra -= nos;

		while(nos--)
		{
		   // cout<<4;
			fi = r.front();
			se = *l.lower_bound(fi);
			ans[fi] = ans[se] = 1;
			r.pop_front();
			l.erase(se);
		}
		while(extra--)
		{
		   // cout<<3;
			fi = r.front();
			se = *l.lower_bound(fi);
			ans[fi] = ans[se] = 0;
			r.pop_front();
			l.erase(se);
		}
	}
	for(int i=0;i<n;i++)
        cout<<ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r;
set<int> l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);
	reverse(r.begin(), r.end());
	while(!r.empty())
	{
		int now = r.back();
		int x = *l.lower_bound(now);
		ans[now] = 1, ans[x] = 1;
		r.pop_back();
		l.erase(x);
		vector<int> nos ;
		while(!r.empty() && r.back() < x)
		{
			nos.push_back(r.back());
			r.pop_back();
		}
		int cnt = 0;
		for(auto i : nos)
		{
			int fi = i;
			int se = *l.lower_bound(fi);
			l.erase(se);
			if(cnt>=nos.size()/2+1)
                ans[fi]=ans[se]=1;
            cnt++;
		}
	}
	for(int i = 0; i < n; i++)
		cout << ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r, l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.push_back(i);
	reverse(r.begin(), r.end());
	while(!r.empty())
	{
		int now = r.back();
		r.pop_back();
		ans[now] = 1;
		int x = *lower_bound(l.begin(), l.end(), now);
		ans[x] = 1;
		while(!r.empty()&&r.back()<x)
            r.pop_back();
	}
	for(int i=0;i<n;i++)
        cout<<ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r;
set<int> l ;
int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);
	reverse(r.begin(), r.end());
	int color=0;
	while(!r.empty())
	{
		int now = r.back();
		int x = *l.lower_bound(now);
		ans[now] = color, ans[x] = color;
		r.pop_back();
		l.erase(x);
		color=1-color;
	}
	for(int i = 0; i < n; i++)
		cout << ans[i];
	return 0 ;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, ans[200009];
string s ;
vector<int> r;
set<int> l ;

int main()
{
	cin >> n >> s;
	for(int i = 0; i < n; i++)
		if(s[i] == '(')
			r.push_back(i);
		else
			l.insert(i);

	reverse(r.begin(), r.end());
	while(!r.empty())
	{
		int now = r.back();
		int x = *l.lower_bound(now);
		ans[now] = 1, ans[x] = 1;
		r.pop_back();
		l.erase(x);
		vector<int> nos ;
		while(!r.empty() && r.back() < x)
		{
			nos.push_back(r.back());
			r.pop_back();
		}
		int cnt = 0;
		for(auto i : nos)
		{
			int fi = i;
			int se = *l.lower_bound(fi);
			l.erase(se);
                ans[fi]=ans[se]=cnt;
            cnt=1-cnt;
		}
	}
	for(int i = 0; i < n; i++)
		cout << ans[i];
	return 0 ;
}


#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
using namespace std;
#define auto vector< char >::iterator
int main()
{
    int n,i,c=0;
    cin>>n;
    string s="";
    cin>>s;int max1=INT_MIN;
    for(i=0;i<n;i++)
    {
        if(s[i]=='(')
            c++;
        else
            c--;
        if(c>max1)
            max1=c;
    }string c1="";int d=0;
    for(i=0;i<n;i++)
    {
        if((s[i]=='(')&&(d==(int)((max1+1)/2)))
        {int e=0;
            while((s[i]!=')')||(e!=1))
            {
                if(s[i]=='(')
                    e++;
                else
                    e--;
                c1=c1+"0";
                i++;
            }
            c1=c1+"0";
        }
        else
        {
        if(s[i]=='(')
            d++;
        else
            d--;
            c1=c1+"1";}
    }
    cout<<c1<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
using namespace std;
#define auto vector< char >::iterator
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,i,c=0;
    cin>>n;
    string s="";
    cin>>s;int max1=INT_MIN;
    for(i=0;i<n;i++)
    {
        if(s[i]=='(')
            c++;
        else
            c--;
        if(c>max1)
            max1=c;
    }string c1="";int d=0;
    for(i=0;i<n;i++)
    {
        if((s[i]=='(')&&(d==(int)((max1+1)/2)))
        {int e=0;
            while((s[i]!=')')||(e!=1))
            {
                if(s[i]=='(')
                    e++;
                else
                    e--;
                c1=c1+"0";
                i++;
            }
            c1=c1+"0";
        }
        else
        {
        if(s[i]=='(')
            d++;
        else
            d--;
            c1=c1+"1";
        }
    }
    cout<<c1<<endl;
    return 0;
}


    #include <bits/stdc++.h>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    #define auto vector< char >::iterator
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n,i,c=0;
        cin>>n;
        string s="";
        cin>>s;int max1=INT_MIN;
        for(i=0;i<n;i++)
        {
            if(s[i]=='(')
                c++;
            else
                c--;
            if(c>max1)
                max1=c;
        }string c1="";int d=0;
        for(i=0;i<n;i++)
        {
            if((s[i]=='(')&&(d==(int)((max1+1)/2)))
            {int e=0;
                while((s[i]!=')')||(e!=1))
                {
                    if(s[i]=='(')
                        e++;
                    else
                        e--;
                    c1+="0";
                    i++;
                }
                c1+="0";
            }
            else
            {
            if(s[i]=='(')
                d++;
            else
                d--;
                c1+="1";
            }
        }
        cout<<c1<<endl;
        return 0;
    }


#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
using namespace std;
#define auto vector< char >::iterator
int main()
{
    int n,i,c=0;
    cin>>n;
    string s="";
    cin>>s;int max1=INT_MIN;
    for(i=0;i<n;i++)
    {
        if(s[i]=='(')
            c++;
        else
            c--;
        if(c>max1)
            max1=c;
    }string c1="";int d=0;
    for(i=0;i<n;i++)
    {
        if((s[i]=='(')&&(d==(int)((max1+1)/2)))
        {int e=0;
            while((s[i]!=')')&&(e!=1))
            {
                if(s[i]=='(')
                    e++;
                else
                    e--;
                c1=c1+"0";
                i++;
            }
            c1=c1+"0";
        }
        else
        {
        if(s[i]=='(')
            d++;
        else
            d--;
            c1=c1+"1";}
    }
    cout<<c1<<endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char A[3000000];

int main(void){
    string ans;
    int N ;
    scanf("%d",&N);
    scanf("%s",A);
    int len = strlen(A);
    int a0 = 0, a1 = 0;
    for(int l=0;l<len;l++){
        if(A[l]=='('){
            if(a0<=a1){
                a0++;
               ans += '0';
            }
            else{
                a1++;
                ans += '1';
            }
        }
        else{
            if(a0>a1){
                a0--;
                ans += '0';
            }
            else{
                a1--;
                ans += '1';
            }
        }
    }
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 5e5 + 5, M = 1e6+6;

int n, ans[N], cnt;
string s;
stack<char> st;

int main(){
    cin >> n >> s;
    for(int i=0;i<n;++i){
        if(s[i]=='('){
            if(cnt%2){
                st.push('0');
                printf("0");
            }else{
                st.push('1');
                printf("1");
            }
            cnt++;
        }else if(s[i]==')'){
            printf("%c",st.top());
            st.pop();
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 5e5 + 5, M = 1e6+6;

int n, ans[N];
string s;
queue<pair<char,int> > qu;

int main(){
    cin >> n >> s;
    char c = ')';
    for(int i=0;i<n;++i){
        if(c==')'&&s[i]!=c){
            ans[i]=1;
            c='(';
        }else if(c=='('&&s[i]!=c){
            ans[i]=1;
            c=')';
        }
    }
    for(int i=0;i<n;++i){
        printf("%d",ans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 5e5 + 5, M = 1e6+6;

int n, ans[N], cnt;
string s;
queue<char> st;

int main(){
    cin >> n >> s;
    for(int i=0;i<n;++i){
        if(s[i]=='('){
            if(cnt%2){
                st.push('0');
                printf("0");
            }else{
                st.push('1');
                printf("1");
            }
            cnt++;
        }else if(s[i]==')'){
            printf("%c",st.front());
            st.pop();
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 5e5 + 5, M = 1e6+6;

int n, ans[N];
string s;
stack<char> st;

int main(){
    cin >> n >> s;
    char c = ')';
    for(int i=0;i<n;++i){
        if(st.empty()&&s[i]=='('){
            st.push(s[i]);
            ans[i]=1;
        }else if(st.top()=='('&&s[i]==')'){
            st.pop();
            ans[i]=1;
        }
    }
    for(int i=0;i<n;++i){
        printf("%d",ans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n,k=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='(') k++,cout<<k%2;
        else cout<<k%2,k--;
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){

    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll sum=1;
    map<ll,ll> m;
    for(int i=0;i<n;i++){
        if(s[i]=='(') sum++,m[sum]=(m[sum-1]^1),cout<<m[sum];
        else{
            cout<<m[sum];sum--;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){

    ll n;
    cin>>n;
    string s;
    cin>>s;
    stack<ll> st;
    for(int i=0;i<n;i++){
        if(s[i]=='('){
            if(st.empty()) {st.push(0);cout<<0;}
            else{
            ll x=st.top();
            x^=1;
            cout<<x;
            st.push(x);
            }
        }
        else{
            ll x=st.top();
            cout<<x;
            st.pop();
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define mx 1e18
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define double long double
ll bino()
{
        vector<ll>inv(200005);vector<ll>fact(200005); vector<ll>inversef(200005);
    inv[0] = 1;inv[1]=1;
for(int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod%i]*(mod-mod/i)) % mod;

    fact[0]=1;
    for(int i=1;i<200005;i++)
    fact[i]=(i*fact[i-1])%mod;

    inversef[0]=1;inversef[1]=1;
    for(int i=2;i<200005;i++)
    inversef[i]=(inversef[i-1]*inv[i])%mod;
}
ll powe(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return powe(((x%mod)*(x%mod))%mod,n/2);
    else                             //n is odd
        return ((x%mod*(powe(((x%mod)*(x%mod))%mod,(n-1)/2))%mod)%mod);
}

int main()
{
   io
int n;cin>>n;
string s;cin>>s;
stack<int>st;int mm=0;
for(int i=0;i<n;i++)
{
    if(s[i]=='(')
    {
        st.push(s[i]);mm=max(mm,(int)st.size());
    }
    else
    {
        if(!st.empty())
        st.pop();
        mm=max(mm,(int)st.size());
    }
}int pp;
if(mm%2==0)
{
    pp=mm/2;
}
else pp=mm/2+1;int yy;int c=0;vector<int>vv(n,0);
for(int i=0;i<n;i++)
{
    if(pp<=st.size()&&s[i]==')')vv[i]=1;
    if(s[i]=='(')st.push(s[i]);
    else st.pop();
}
for(int i=0;i<n;i++)cout<<vv[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define mx 1e18
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define double long double
ll bino()
{
        vector<ll>inv(200005);vector<ll>fact(200005); vector<ll>inversef(200005);
    inv[0] = 1;inv[1]=1;
for(int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod%i]*(mod-mod/i)) % mod;

    fact[0]=1;
    for(int i=1;i<200005;i++)
    fact[i]=(i*fact[i-1])%mod;

    inversef[0]=1;inversef[1]=1;
    for(int i=2;i<200005;i++)
    inversef[i]=(inversef[i-1]*inv[i])%mod;
}
ll powe(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return powe(((x%mod)*(x%mod))%mod,n/2);
    else                             //n is odd
        return ((x%mod*(powe(((x%mod)*(x%mod))%mod,(n-1)/2))%mod)%mod);
}

int main()
{
   io
int n;cin>>n;
string s;cin>>s;
stack<int>st;int mm=0;
for(int i=0;i<n;i++)
{
    if(s[i]=='(')
    {
        st.push(s[i]);mm=max(mm,(int)st.size());
    }
    else
    {
        if(!st.empty())
        st.pop();
        mm=max(mm,(int)st.size());
    }
}int pp;
if(mm%2==0)
{
    pp=mm/2;
}
else pp=mm/2+1;int yy;int c=0;vector<int>vv;
for(int i=0;i<s.length();i++)
{
    if(s[i]=='(')c++;
    else c--;
    vv.pb(i);
    if(c==pp)
    {yy=i+1;
       break;
    }
}
for(int i=yy;i<n;i++)
{
    if(s[i]==')'){vv.pb(i);c--;}
    if(c==0)break;
}
vector<int>u(n,1);
for(int i=0;i<vv.size();i++)
{
    u[vv[i]]=0;
}
for(int i=0;i<n;i++)cout<<u[i];

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define mx 1e18
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define double long double
ll bino()
{
        vector<ll>inv(200005);vector<ll>fact(200005); vector<ll>inversef(200005);
    inv[0] = 1;inv[1]=1;
for(int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod%i]*(mod-mod/i)) % mod;

    fact[0]=1;
    for(int i=1;i<200005;i++)
    fact[i]=(i*fact[i-1])%mod;

    inversef[0]=1;inversef[1]=1;
    for(int i=2;i<200005;i++)
    inversef[i]=(inversef[i-1]*inv[i])%mod;
}
ll powe(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return powe(((x%mod)*(x%mod))%mod,n/2);
    else                             //n is odd
        return ((x%mod*(powe(((x%mod)*(x%mod))%mod,(n-1)/2))%mod)%mod);
}

int main()
{
   io
int n;cin>>n;
string s;cin>>s;
stack<int>st;int mm=0;
for(int i=0;i<n;i++)
{
    if(s[i]=='(')
    {
        st.push(s[i]);mm=max(mm,(int)st.size());
    }
    else
    {
        if(!st.empty())
        st.pop();
        mm=max(mm,(int)st.size());
    }
}int pp;
if(mm%2==0)
{
    pp=mm/2;
}
else pp=mm/2;int yy;int c=0;vector<int>vv(n,0);
for(int i=0;i<n;i++)
{
    if(pp==st.size()&&s[i]==')')vv[i]=1;
    if(pp>st.size())vv[i]=1;
    if(s[i]=='(')st.push(s[i]);
    else st.pop();
}
for(int i=0;i<n;i++)cout<<vv[i];

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define mx 1e18
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define double long double
ll bino()
{
        vector<ll>inv(200005);vector<ll>fact(200005); vector<ll>inversef(200005);
    inv[0] = 1;inv[1]=1;
for(int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod%i]*(mod-mod/i)) % mod;

    fact[0]=1;
    for(int i=1;i<200005;i++)
    fact[i]=(i*fact[i-1])%mod;

    inversef[0]=1;inversef[1]=1;
    for(int i=2;i<200005;i++)
    inversef[i]=(inversef[i-1]*inv[i])%mod;
}
ll powe(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return powe(((x%mod)*(x%mod))%mod,n/2);
    else                             //n is odd
        return ((x%mod*(powe(((x%mod)*(x%mod))%mod,(n-1)/2))%mod)%mod);
}

int main()
{
   io
int n;cin>>n;
string s;cin>>s;
stack<int>st;int mm=0;
for(int i=0;i<n;i++)
{
    if(s[i]=='(')
    {
        st.push(s[i]);mm=max(mm,(int)st.size());
    }
    else
    {
        if(!st.empty())
        st.pop();
        mm=max(mm,(int)st.size());
    }
}int pp;
if(mm%2==0)
{
    pp=mm/2;
}
else pp=mm/2;int yy;int c=0;vector<int>vv(n,0);
for(int i=0;i<n;i++)
{
    if(pp==st.size()&&s[i]==')')vv[i]=1;
    if(pp>st.size())vv[i]=1;
    if(s[i]=='(')st.push(s[i]);
    else st.pop();
}
for(int i=0;i<n;i++)cout<<vv[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define mx 1e18
#define mod 1000000007
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define double long double
ll bino()
{
        vector<ll>inv(200005);vector<ll>fact(200005); vector<ll>inversef(200005);
    inv[0] = 1;inv[1]=1;
for(int i = 2; i < 200005; ++i)
    inv[i] = (inv[mod%i]*(mod-mod/i)) % mod;

    fact[0]=1;
    for(int i=1;i<200005;i++)
    fact[i]=(i*fact[i-1])%mod;

    inversef[0]=1;inversef[1]=1;
    for(int i=2;i<200005;i++)
    inversef[i]=(inversef[i-1]*inv[i])%mod;
}
ll powe(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return powe(((x%mod)*(x%mod))%mod,n/2);
    else                             //n is odd
        return ((x%mod*(powe(((x%mod)*(x%mod))%mod,(n-1)/2))%mod)%mod);
}

int main()
{
   io
int n;cin>>n;
string s;cin>>s;
stack<int>st;int mm=0;
for(int i=0;i<n;i++)
{
    if(s[i]=='(')
    {
        st.push(s[i]);mm=max(mm,(int)st.size());
    }
    else
    {
        if(!st.empty())
        st.pop();
        mm=max(mm,(int)st.size());
    }
}int pp;
if(mm%2==0)
{
    pp=mm/2;
}
else pp=mm/2+1;int yy;int c=0;vector<int>vv;
for(int i=0;i<s.length();i++)
{
    if(s[i]=='(')c++;
    else c--;
    vv.pb(i);
    if(c==pp)
    {yy=i+1;
       break;
    }
}
for(int i=yy;i<n;i++)
{
    if(s[i]==')')vv.pb(i);c--;
    if(c==0)break;
}
vector<int>u(n,1);
for(int i=0;i<vv.size();i++)
{
    u[vv[i]]=0;
}
for(int i=0;i<n;i++)cout<<u[i];

}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int N; cin >> N;
    string S; cin >> S;
    S = "." + S;

    vector<int> open(N + 1, 0), close(N + 1, 0);

    int total_depth = 0;
    {
        int tmp = 0;
        for (int i = 1; i <= N; i++)
        {
            if (S[i] == '(')
            {
                tmp++;
                open[i]++;
                close[i] = close[i - 1];
            }
            else
            {
                tmp--;
                close[i]++;
                open[i] = open[i - 1];
            }

            total_depth = max(total_depth, tmp);
        }
    }

    int max_r = total_depth / 2;
    int max_b = total_depth - max_r;

    if (max_r < max_b) swap(max_r, max_b);

    vector<int> ans(N + 1, -1);

    int br = 1, er = N;
    for (int i = 1, o = 0; i <= N && o < max_r - 1; i++)
    {
        if (S[i] == '(')
        {
            o++;
            ans[i] = 0;
            br = i;
        }
    }

    for (int i = N, c = 0; i >= 1 && c < max_r - 1; i--)
    {
        if (S[i] == ')')
        {
            c++;
            ans[i] = 0;
            er = i;
        }
    }

    for (int i = br + 1, k = 0; i < er; i++)
    {
        int cr = close[er - 1] - close[i - 1];

        if (S[i] == '(' && cr > 0 && k == 0)
        {
            ans[i] = 0;
            k++;
        }
        else if (S[i] == ')' && k == 1)
        {
            ans[i] = 0;
            k--;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        if (ans[i] == -1) ans[i] = 1;
        cout << ans[i];
    }

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int N; cin >> N;
    string S; cin >> S;
    S = "." + S;

    vector<int> open(N + 1, 0), close(N + 1, 0);

    int total_depth = 0;
    {
        int tmp = 0;
        for (int i = 1; i <= N; i++)
        {
            open[i] = open[i - 1];
            close[i] = close[i - 1];

            if (S[i] == '(')
            {
                tmp++;
                open[i]++;
            }
            else
            {
                tmp--;
                close[i]++;
            }

            total_depth = max(total_depth, tmp);
        }
    }

    int max_r = total_depth / 2;
    int max_b = total_depth - max_r;

    if (max_r > max_b) swap(max_r, max_b);

    vector<int> ans(N + 1, -1);

    int br = 0, er = N + 1;
    for (int i = 1, o = 0; i <= N && o < max_r - 1; i++)
    {
        if (S[i] == '(')
        {
            o++;
            ans[i] = 0;
            br = i;
        }
    }

    for (int i = N, c = 0; i >= 1 && c < max_r - 1; i--)
    {
        if (S[i] == ')')
        {
            c++;
            ans[i] = 0;
            er = i;
        }
    }

    for (int i = br + 1, k = 0; i < er; i++)
    {
        int cr = close[er - 1] - close[i - 1];

        if (S[i] == '(' && cr > 0 && k == 0)
        {
            ans[i] = 0;
            k++;
        }
        else if (S[i] == ')' && k == 1)
        {
            ans[i] = 0;
            k--;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        if (ans[i] == -1) ans[i] = 1;
        cout << ans[i];
    }

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int N; cin >> N;
    string S; cin >> S;
    S = "." + S;

    int total_depth = 0;
    {
        int tmp = 0;
        for (int i = 1; i <= N; i++)
        {
            if (S[i] == '(') tmp++;
            else tmp--;

            total_depth = max(total_depth, tmp);
        }
    }

    int max_r = total_depth / 2;
    int max_b = total_depth - max_r;

    if (max_b > max_r) swap(max_b, max_r);

    vector<int> ans(N + 1, -1);
    for (int i = 1, o = 0, c = 0; i <= N; i++)
    {
        if (S[i] == '(' && o < max_r)
        {
            ans[i] = 0;
            o++;
        }
        else if (S[i] == ')' && c < max_r)
        {
            ans[i] = 0;
            c++;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        if (ans[i] == -1) ans[i] = 1;
    }

    for (int i = 1; i <= N; i++) cout << ans[i];

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int N; cin >> N;
    string S; cin >> S;
    S = "." + S;

    vector<int> open(N + 1, 0), close(N + 1, 0);

    int total_depth = 0;
    {
        int tmp = 0;
        for (int i = 1; i <= N; i++)
        {
            open[i] = open[i - 1];
            close[i] = close[i - 1];

            if (S[i] == '(')
            {
                tmp++;
                open[i]++;
            }
            else
            {
                tmp--;
                close[i]++;
            }

            total_depth = max(total_depth, tmp);
        }
    }

    int max_r = total_depth / 2;
    int max_b = total_depth - max_r;

    vector<int> ans(N + 1, -1);

    for (int i = 1, o = 0; i <= N; i++)
    {
        int cr = close[N] - close[i - 1];
        if (S[i] == '(' && o < max_r && cr >= max_r)
        {
            ans[i] = 0;
            o++;
        }
        else if (S[i] == ')' && o > 0)
        {
            ans[i] = 0;
            o--;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        if (ans[i] == -1) ans[i] = 1;
        cout << ans[i];
    }

    return 0;
}


/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num, int pos);
ll setbitt(ll num, ll pos);
ll resetbitt(ll num, int pos);

//.................___Start from here___.................//
//.................._____________________................//

int solve() {
	int n;
	cin >> n;
	stack<int> pos;
	int nest[n];
	string s;
	cin >> s;
	int p  = 0;
	int mxp = 0;
	int i = 0;
	for (auto x : s) {
		if (x == '(') p++, pos.push(i);
		else p--, nest[pos.top()] = i, pos.pop();
		mxp = max(mxp, p);
		i++;
	}
	int color[n];
	clr(color);
	fri(n) {
		if (s[i] == ')' && s[i - 1] == '(') {
			color[i] = 1;
			color[i - 1] = 1;
		}
		// else color[i] = 2;
	}

	// cout << mxp << endl;
	int mx = ceil(mxp / 2.0);
	mx--;
	// cout << mx << endl;
	for (int i = 0; i < n && mx; i++) {
		if (s[i] == '(' && color[i] == 0) {
			color[i] = 1;
			color[nest[i]] = 1;
			// cout << i << endl;
			mx--;

		}
	}

	for (auto x : color) cout << x;
	cout << endl;

	return 0;
}
int main() {
#ifndef ONLINE_JUDGE
	input;
	output;
#endif
	int cs = 1;
	int cn = 1;
	//cin>>cs;
	while (cs--) {
		solve();

	}
}

bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}


/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num, int pos);
ll setbitt(ll num, ll pos);
ll resetbitt(ll num, int pos);

//.................___Start from here___.................//
//.................._____________________................//

int solve() {
	int n;
	cin >> n;
	stack<int> pos;
	int nest[n];
	reset(nest, -1);
	string s;
	cin >> s;
	int p  = 0;
	int mxp = 0;
	int i = 0;
	for (auto x : s) {
		if (x == '(') p++, pos.push(i);
		else p--, nest[i] = pos.top(), pos.pop();
		mxp = max(mxp, p);
		i++;
	}
	int color[n];
	clr(color);

	p = 0;
	int q = ceil(mxp / 2.0);

	fri(n) {
		// cout << nest[i] << endl;
		if (s[i] == '(' && q) {
			q--;
			p++;
			color[i] = 1;

		}
		else if (nest[i] != -1 && color[nest[i]] == 1) {
			p--;
			color[i] = 1;

		}
		if (p == 0) {
			q = ceil(mxp / 2.0);

		}
	}

	for (auto x : color) cout << x;
	cout << endl;

	return 0;
}
int main() {
#ifndef ONLINE_JUDGE
	input;
	output;
#endif
	int cs = 1;
	int cn = 1;
	//cin>>cs;
	while (cs--) {
		solve();

	}
}

bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}


/*
    Bismillahir Rahmanir Raheem
    Think Twice Code Once
    author : reaziii
*/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num, int pos);
ll setbitt(ll num, ll pos);
ll resetbitt(ll num, int pos);

//.................___Start from here___.................//
//.................._____________________................//

int solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int b = 0;
	int i = 0;
	int color[n];
	clr(color);
	for (auto c : s) {
		if (c == '(') b++;
		// cout << b << endl;
		color[i] = (b & 1);
		if (c == ')') b--;
		i++;
	}

	for (auto x : color) cout << x;
	cout << endl;

	return 0;
}
int main() {
#ifndef ONLINE_JUDGE
	input;
	output;
#endif
	int cs = 1;
	int cn = 1;
	//cin>>cs;
	while (cs--) {
		solve();

	}
}

bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}