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