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