#include<iostream>
using namespace std;
int main()
{
    long long n1;
    long long n2;
    long long k;
    char c1;
    char c2;
    cin>>n1>>c1;
    cin>>n2>>c2;
    cin>>k;
    if(c1 == 'A')
    {
        if(n1 > k)
        {
            cout<<k;
        }
        else
        {
            cout<<n1;
        }
    }
    if(c1 == 'B')
    {
        if(n1 >= k)
        {
            cout<<"0";
        }
        else
        {
            cout<<k-n1;
        }
    }
    return 0;
}