#include <iostream>
#include <cmath>
#include <string>
using namespace std;
//解题思路:逆序遍历字符串,构建映射关系:A-10、B-11、C-12、D-13、E-14、F-15
int main() {
string str;
while(cin>>str){
int N=str.size();
int number=0;
int count = 0;
for(int i=N-1; i>=2; i--,count++){
int temp;
if(str[i]>64){//A~F与真实十六进制值差了55
temp = str[i]-55;
}else{//正常的0~9的数字
temp = stoi(str.substr(i,1));
}
number += temp*pow(16,count);
}
cout<<number<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")



京公网安备 11010502036488号