#include<iostream>
using namespace std;
int main()
{
    long long n1,n2,k,ost;
    int kos;
    int zos;
    char c1,c2;
    cin>>n1>>c1;
    cin>>n2>>c2;
    cin>>k;
    if(k<n1 && c1=='B')
    {
        cout<<"0";
    }
    if(n1<k && c1=='A')
    {
        cout<<n1;
    }

    return 0;
}
