#include<iostream>
using namespace std;
int main(){
    int n1,n2,k;
    char c1,c2;
    cin>>n1>>c1;
    cin>>n2>>c2;
    cin>>k;
    if(c1=='A'){
        if(k<n1){
            cout<<k<<endl;
        }else{
            cout<<n1<<endl;
        }
    }
    else if(c2='A'){
        if(k<n1){
            cout<<"0"<<endl;
        }else{
            cout<<k-n1<<endl;
    }
    }

return 0;
}

