#include<iostream>
using namespace std;
int main(){
long long n1,n2,k,vareli,nevareli;
char c1,c2;
vareli=0;
nevareli=0;
cin>>n1>>c1>>n2>>c2>>k;

if(c2=='B' and k>c2){
        vareli=k-c2;
}
if(c1=='B' and k>c1){
    vareli=k-c1;
}
if(c2=='B' and k<c2){
        vareli=c2-k;
}
if(c1=='B' and k<c1){
    vareli=c1-k;
}
cout<<vareli;
return 0;
}
