#include <iostream>
#include <charconv>
#include <cmath>
using namespace std;



int main ()
{
    int n1, n2, k;
    char c1, c2, A, B;
    cin >> n1 >>c1 >> n2 >>c2 >> k;
    if (c1=A)
    {
        cout << min (k,n1) <<endl;
    }
    else if (c1=B &k >n1)
    {
        cout << k -n1<<endl;
    }
    else if (c1=B & k<n1 )
    {
        cout << 0 <<endl;
    }

    return 0;
}
