#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    long long b1,b2;
    long long kacheni;
    char c1,c2;
    cin>>b1>>c1;
    cin>>b2>>c2;
    cin>>kacheni;
    if(c1=='A')
    {
        if(b1<=kacheni)cout<<b1;
        else cout<<kacheni;
    }
    else
    {
        if(b1>=kacheni)cout<<0;
        else cout<<kacheni-b1;
    }
}
