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