#include<iostream>
using namespace std;
int main()
{
long long brlqvo,brdqsno,k,sbr;
char simbol1,simbol2;
cin>>brlqvo>>simbol1;
cout<<"\n";
cin>>brdqsno>>simbol2;
cout<<"\n";
cin>>k;
long long izh;
if(simbol1=='A')
{
izh=izh+brlqvo;
sbr=brlqvo;
}
else
{
izh=izh+brdqsno;
sbr=brdqsno;
}
if(k>sbr)
{
izh=k-sbr;
}
cout<<izh;
return 0;
}