#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const int M = 3e3 + 5;
const int MAXX = 1e8;
int dp[M][M][2];
set<int> evenRows, evenCols, oddRows, oddCols;
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
int n, m;
bool inside(int x, int y){
return (x >= 1 && x <= n && y >= 1 && y <= m);
}
int main(){
for(int i = 1 ; i < M ; i++){
for(int j = 1 ; j < M ; j++){
for(int k = 0 ; k < 3 ; k++){
dp[i][j][k] = MAXX;
}
}
}
int k;
cin >> n >> m >> k;
for(int i = 1 ; i <= k ; i++){
int x, y;
char ch;
si(x); si(y); cin >> ch;
if(ch == 'R'){
evenRows.insert(x);
oddCols.insert(y);
// cout<<"even row "<<x <<" odd col "<<y<<endl;
}
else{
oddRows.insert(x);
evenCols.insert(y);
// cout<<"odd row "<<x <<" even col "<<y<<endl;
}
}
dp[1][1][0] = 0;
// x, y, even, odd
queue<pair<int, pair<int, int> > > Q;
Q.push({1, {1, 0}});
// set<pair<int, pair<int, int> > > se;
// se.insert({1, {1, 0}});
while(Q.size()){
pair<int, pair<int, int> > p = Q.front();
int curX = p.first;
int curY = p.second.first;
int evenn = p.second.second;
Q.pop();
if(dp[curX][curY][evenn] >= MAXX) continue;
for(int d = 0 ; d < 4 ; d++){
int nx = curX + dx[d];
int ny = curY + dy[d];
if(!inside(nx, ny)) continue;
if(evenn){
// odd should not have it
if(oddRows.count(nx) || oddCols.count(ny)){
continue;
}
if(dp[nx][ny][1 - evenn] >= MAXX){
dp[nx][ny][1 - evenn] = dp[curX][curY][evenn] + 1;
Q.push({nx, {ny, 1 - evenn}});
}
}
else{
// even should not have it
if(evenRows.count(nx) || evenCols.count(ny)){
continue;
}
if(dp[nx][ny][1 - evenn] >= MAXX){
dp[nx][ny][1 - evenn] = dp[curX][curY][evenn] + 1;
Q.push({nx, {ny, 1 - evenn}});
}
}
// cout<<"ok "<<nx<<". "<<ny<<" "<<1 - evenn<<" "<<dp[nx][ny][1 - evenn]<<endl;
}
}
int ans = min(dp[n][m][0], dp[n][m][1]);
if(ans >= MAXX){
ans = -1;
}
cout<<ans;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxzdHJpbmc+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgdWxsIHVuc2lnbmVkIGxvbmcgbG9uZwojZGVmaW5lIHNpKFgpIHNjYW5mKCIlZCIsICYoWCkpCiNkZWZpbmUgc2xsKFgpIHNjYW5mKCIlbGxkIiwmKFgpKQogCmNvbnN0IGludCBNID0gM2UzICsgNTsKY29uc3QgaW50IE1BWFggPSAxZTg7CiAKaW50IGRwW01dW01dWzJdOwogCnNldDxpbnQ+IGV2ZW5Sb3dzLCBldmVuQ29scywgb2RkUm93cywgb2RkQ29sczsKaW50IGR4WzhdID0gezEgLCAwICwgLTEgLCAwICwgMSAsIC0xICwgLTEgLCAxfTsgICAgLy8gbGFzdCA0IGRpYWdvbmFsCmludCBkeVs4XSA9IHswICwgMSAsIDAgLCAtMSAsIDEgLCAxICwgLTEgLCAtMX07CiAKaW50IG4sIG07CiAKYm9vbCBpbnNpZGUoaW50IHgsIGludCB5KXsKICAgIHJldHVybiAoeCA+PSAxICYmIHggPD0gbiAmJiB5ID49IDEgJiYgeSA8PSBtKTsKfQogCmludCBtYWluKCl7CiAKICAgIGZvcihpbnQgaSA9IDEgOyBpIDwgTSA7IGkrKyl7CiAgICAgICAgZm9yKGludCBqID0gMSA7IGogPCBNIDsgaisrKXsKICAgICAgICAgICAgZm9yKGludCBrID0gMCA7IGsgPCAzIDsgaysrKXsKICAgICAgICAgICAgICAgIGRwW2ldW2pdW2tdID0gTUFYWDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KIAogICAgaW50IGs7CiAgICBjaW4gPj4gbiA+PiBtID4+IGs7CiAKIAogICAgZm9yKGludCBpID0gMSA7IGkgPD0gayA7IGkrKyl7CiAgICAgICAgaW50IHgsIHk7CiAgICAgICAgY2hhciBjaDsKICAgICAgICBzaSh4KTsgIHNpKHkpOyAgY2luID4+IGNoOwogICAgICAgIGlmKGNoID09ICdSJyl7CiAgICAgICAgICAgIGV2ZW5Sb3dzLmluc2VydCh4KTsKICAgICAgICAgICAgb2RkQ29scy5pbnNlcnQoeSk7CiAgICAgICAgICAgLy8gY291dDw8ImV2ZW4gcm93ICI8PHggPDwiIG9kZCBjb2wgIjw8eTw8ZW5kbDsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgb2RkUm93cy5pbnNlcnQoeCk7CiAgICAgICAgICAgIGV2ZW5Db2xzLmluc2VydCh5KTsKICAgICAgICAgICAvLyBjb3V0PDwib2RkIHJvdyAiPDx4IDw8IiBldmVuIGNvbCAiPDx5PDxlbmRsOwogCiAgICAgICAgfQogICAgfQogCiAgICBkcFsxXVsxXVswXSA9IDA7CiAgICAvLyB4LCB5LCBldmVuLCBvZGQKICAgIHF1ZXVlPHBhaXI8aW50LCBwYWlyPGludCwgaW50PiA+ID4gUTsKICAgIFEucHVzaCh7MSwgezEsIDB9fSk7CiAKICAgLy8gc2V0PHBhaXI8aW50LCBwYWlyPGludCwgaW50PiA+ID4gc2U7CiAgIC8vIHNlLmluc2VydCh7MSwgezEsIDB9fSk7CiAKICAgIHdoaWxlKFEuc2l6ZSgpKXsKICAgICAgICBwYWlyPGludCwgcGFpcjxpbnQsIGludD4gPiBwID0gUS5mcm9udCgpOwogCiAgICAgICAgaW50IGN1clggPSBwLmZpcnN0OwogICAgICAgIGludCBjdXJZID0gcC5zZWNvbmQuZmlyc3Q7CiAgICAgICAgaW50IGV2ZW5uID0gcC5zZWNvbmQuc2Vjb25kOwogICAgICAgIFEucG9wKCk7CiAKICAgICAgICBpZihkcFtjdXJYXVtjdXJZXVtldmVubl0gPj0gTUFYWCkgY29udGludWU7CiAKIAogICAgICAgIGZvcihpbnQgZCA9IDAgOyBkIDwgNCA7IGQrKyl7CiAgICAgICAgICAgIGludCBueCA9IGN1clggKyBkeFtkXTsKICAgICAgICAgICAgaW50IG55ID0gY3VyWSArIGR5W2RdOwogICAgICAgICAgICBpZighaW5zaWRlKG54LCBueSkpIGNvbnRpbnVlOwogCiAgICAgICAgICAgIGlmKGV2ZW5uKXsKICAgICAgICAgICAgICAgIC8vIG9kZCBzaG91bGQgbm90IGhhdmUgaXQKICAgICAgICAgICAgICAgIGlmKG9kZFJvd3MuY291bnQobngpIHx8IG9kZENvbHMuY291bnQobnkpKXsKICAgICAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGRwW254XVtueV1bMSAtIGV2ZW5uXSA+PSBNQVhYKXsKICAgICAgICAgICAgICAgICAgICBkcFtueF1bbnldWzEgLSBldmVubl0gPSBkcFtjdXJYXVtjdXJZXVtldmVubl0gKyAxOwogICAgICAgICAgICAgICAgICAgIFEucHVzaCh7bngsIHtueSwgMSAtIGV2ZW5ufX0pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICAvLyBldmVuIHNob3VsZCBub3QgaGF2ZSBpdAogICAgICAgICAgICAgICAgaWYoZXZlblJvd3MuY291bnQobngpIHx8IGV2ZW5Db2xzLmNvdW50KG55KSl7CiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZihkcFtueF1bbnldWzEgLSBldmVubl0gPj0gTUFYWCl7CiAgICAgICAgICAgICAgICAgICAgZHBbbnhdW255XVsxIC0gZXZlbm5dID0gZHBbY3VyWF1bY3VyWV1bZXZlbm5dICsgMTsKICAgICAgICAgICAgICAgICAgICBRLnB1c2goe254LCB7bnksIDEgLSBldmVubn19KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgIC8vIGNvdXQ8PCJvayAiPDxueDw8Ii4gIjw8bnk8PCIgIjw8MSAtIGV2ZW5uPDwiICI8PGRwW254XVtueV1bMSAtIGV2ZW5uXTw8ZW5kbDsKICAgICAgICB9CiAKIAogICAgfQogCiAgICBpbnQgYW5zID0gbWluKGRwW25dW21dWzBdLCBkcFtuXVttXVsxXSk7CiAgICBpZihhbnMgPj0gTUFYWCl7CiAgICAgICAgYW5zID0gLTE7CiAgICB9CiAgICBjb3V0PDxhbnM7CiAKIAp9