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

    return 0;
}