while 1:
try:
string = '0123456789ABCDEF'
string_dict = {}
for i , j in enumerate(string):
string_dict[j] = i
aim_num = input().lstrip("0x")
change_num = 0
for i in range(len(aim_num)):
change_num += string_dict[aim_num[i]](16*(len(aim_num) -i - 1))
print(change_num)
except:
break