import sys input = sys.stdin.readline L, S = input().split() A = [390,429,468,507,546] L = int(L) L-=1 if S=="Beat": L+=1 print(A[L])