#include<iostream>

using namespace std;

int main()
{
    char c1;
    char c2;
    int n2;
    int n1;
    int k;
    cin >> n1 >> c1;
    cin >> n2 >> c2;
    cin >> k;
    if ( c1 == 'A')
    {
     if (k > n1)
    {
        cout << n1 << endl;
    }
    if (k < n1)
    {
        cout << k << endl;
    }
    }
    if (c2 == 'A')
    {
     if (k > n1)
     {
         cout << k-n1 << endl;
     }
     if (k < n1)
     cout << 0;
    }
    return 0;
}