#include<bits/stdc++.h>
using namespace std;

int main() {
    int a, b, c;
    char x, y;
    cin >> a >> x >> b >> y >> c;

    if (x == 'A') {
        if (a <= c) {
            cout << a << '\n';
            return 0;
        }
        else {
            cout << c << '\n';
        }
    }
    else {
        if (a < c) {
            cout << c - a << '\n';
            return 0;
        }
        else {
            cout << "0" << '\n';
            return 0;
        }
    }
    return 0;
}
