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