#include<iostream>
using namespace std;
int main(){

int n1, n2;
char c1, c2;
int k;

cin>>n1>>c1>>n2>>c2>>k;

if(k >= n1 && c1 == 'A'){
    cout<<n1;
}else if(k > n1){
    if(k < n1 + n2){
        cout<<k - n1;
    }else{
        cout<<n2;
    }
}else if(c1 == 'A'){
    cout<<k;
}else{
    cout<<0;
}


    return 0 ;
}
