L, S = input().split() L = int(L) ex = [390, 429, 468, 507, 546] if S == "Beat": print(ex[L]) else: print(ex[L - 1])