l, s = map(str, input().split()) l = int(l) if s != "Beat": l -= 1 print([390,429,468,507,546][l])