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