N,S = input().split() N = int(N) if(S == "Beat"): N += 1 ans = [390,429,468,507,546] print(ans[N-1])