#include<iostream>
using namespace std;
int main()
{
    long long n1,n2,k,ost;
    int sbor;
    int sled_sbor;
    int sled_sled_sbor;
    char c1,c2;
    cin>>n1>>c1;
    cin>>n2>>c2;
    cin>>k;
    if(k<n1 && c1=='B')
    {
        cout<<"0";
    }
    if(n1<k && c1=='A')
    {
        cout<<n1;
    }
    if(k>n1 && c1=='B')
    {
        sbor=n1+n2;
        sled_sbor=sbor-k;
        sled_sled_sbor=n2-sled_sbor;
        cout<<sled_sled_sbor;
    }

    return 0;
}
