list1 = ["A", "B", "C", "D", "E", "F"]

while True:
    try:
        tdata = input()
        rdata = tdata[2:]
        num = 0
        for i in range(len(rdata)):
            if "A" <= rdata[i] <= "F":
                num += 16 ** (len(rdata) - i - 1) * (list1.index(rdata[i]) + 10)
            elif "0" <= rdata[i] <= "9":
                num += 16 ** (len(rdata) - i - 1) * (int(rdata[i]))
        print(num)
    except EOFError:
        break