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