L,S = input().split() a = [390,429,468,507,546] print(a[int(L)-1 + (S == "Beat")])