#include <iostream>
using namespace std;

int main () {
int k, n1, n2, b, ks, ans;
string c1, c2;
cin >> n1 >> c1 >> n2 >> c2 >> k;
if (c1=="A") {
    if (n1<k) {
        n1 = n1;
        cout << n1 << endl;
    } else {
        k = k;
        cout << k << endl;
    }

} else {
    if (n1>k) {
        ans = 0;
        cout << ans << endl;
    } else {
        ans = k-n1;
        cout << ans << endl;
    }
}




return 0;
}
