#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
/*int scan(){
int n=0;
int ch=getchar_unlocked();
while(ch<48)
ch=getchar_unlocked();
while(ch>47)
n=(n<<3)+(n<<1)+ch+'0',ch=getchar_unlocked();
return n;
}*/
int main(){
int n ,q,r,s,t=0,u=0;
char c[10];
cin>>n>>q;
int *col=(int *)calloc(n,sizeof(int));
int *row=(int *)calloc(n,sizeof(int));
while(q--){
//scanf("%s",c); /* SOME ERROR HERE and how to use getchar_unlocked for char here*/
cin>>c>>r>>s;
if(c[0]=='R'){
row[r-1]+=s;
if(row[r-1]>u)
u=row[r-1];
}
else {
col[r-1]+=s;
if(col[r-1]>t)
t=col[r-1];
}
}
printf("%d",t+u);
free(row); free(col);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwovKmludCBzY2FuKCl7CmludCBuPTA7CmludCBjaD1nZXRjaGFyX3VubG9ja2VkKCk7CndoaWxlKGNoPDQ4KQogICAgY2g9Z2V0Y2hhcl91bmxvY2tlZCgpOwp3aGlsZShjaD40NykKICAgIG49KG48PDMpKyhuPDwxKStjaCsnMCcsY2g9Z2V0Y2hhcl91bmxvY2tlZCgpOwpyZXR1cm4gbjsKfSovCmludCBtYWluKCl7CmludCBuICxxLHIscyx0PTAsdT0wOwpjaGFyIGNbMTBdOwpjaW4+Pm4+PnE7CmludCAqY29sPShpbnQgKiljYWxsb2MobixzaXplb2YoaW50KSk7CmludCAqcm93PShpbnQgKiljYWxsb2MobixzaXplb2YoaW50KSk7CndoaWxlKHEtLSl7Ci8vc2NhbmYoIiVzIixjKTsgICAgIC8qIFNPTUUgRVJST1IgSEVSRSAgIGFuZCBob3cgdG8gdXNlIGdldGNoYXJfdW5sb2NrZWQgZm9yIGNoYXIgaGVyZSovCmNpbj4+Yz4+cj4+czsKaWYoY1swXT09J1InKXsKICAgIHJvd1tyLTFdKz1zOwogICAgaWYocm93W3ItMV0+dSkKICAgICAgICB1PXJvd1tyLTFdOwp9CmVsc2UgewogICAgY29sW3ItMV0rPXM7CiAgICBpZihjb2xbci0xXT50KQogICAgICAgIHQ9Y29sW3ItMV07Cn0KfQpwcmludGYoIiVkIix0K3UpOwpmcmVlKHJvdyk7IGZyZWUoY29sKTsKcmV0dXJuIDA7Cn0K