#include //#include using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int L; string S; cin >> L >> S; L--; vector v = {390,429,468,507,546}; cout << (S[0] == 'B' ? v[L+1] : v[L]) << endl; return 0; }