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