#include<iostream>
using namespace std;
int main()
{
    long long n1, n2, k;
    char gorivo[2];
    cin>>n1>>gorivo[1]>>n2>>gorivo[2]>>k;
    if(gorivo[1] == 'A' && k > n1)
    {
        cout<<n1;
    }
    else if(gorivo[1] == 'A' && k < n1)
    {
        cout<<k;
    }
    else if(gorivo[1] == 'B')
    {
        if(k - n1 >= 0)
        {
            cout<<k - n1;
        }
        else
        {
            cout<<"0";
        }
    }
    return 0;
}
