#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 (k>n1){
        cout<<n1;
    }else{
    cout<<k;
    }
} if(c1=='B'){
if(k>n1){
n1=k-n1;
cout<<n1;
}
else{
    cout<<"0";
}


}










return 0;
}
