d = [390,429,468,507,546] l, s = input().split() l = int(l) print(d[l] if s == "Beat" else d[l-1])