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

}
