s = input().strip()
if any(c.islower() for c in s):
    print("Invalid input")
elif not s.isascii() or len(s) == 0:
    print("Invalid input")
else:
    total = 0
    for c in s:
        if not ('A'<= c <= 'z'):
            print("Invalid input")
            break
        total = total * 26 + (ord(c)- ord('A') + 1)
    else:
        print(total)