#include <iostream>
using namespace std;

int main () {

char n1, c1, n2, c2, k;
int n2vz, otg, A;
cin >> n1 >> c1;
cin >> n2 >> c2;
cin >> k ;



if (k>n1)
{
n2vz = k - n1;
}
if (c1 == A) { otg == n2vz;}
if (c2 == A) {otg == n1;}

cout << otg <<endl;
return 0;
}
