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