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