#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n1, n2, k, A=0;
    char c1, c2;
    cin>>n1>>c1;
    cin>>n2>>c2;
    cin>>k;
    if(c1=='A')
    {
        if(k>=n1)A+=n1;
        else A+=k;
    }
    else
    {
        if(k>=n1)A+=k-n1;
    }
    cout<<A;
    return 0;
}
