#include <iostream>
#include <string>
#include <math.h>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[]) {
string hexDecimal;
cin >> hexDecimal;
int i = 0;
int length = (int)hexDecimal.size();//最后一个元素的索引值
// int num = 0;
int64_t num = 0;
int temp = 0;
for (i = 0; i < length; i ++) {
if (hexDecimal[i]>='A' && hexDecimal[i]<='F') {
temp = hexDecimal[i] - 'A' + 10;
}else{
temp = hexDecimal[i] - '0';//必须减‘0’,否则会出现意料意外地bug
}
num += temp * pow(16, length - i-1);
}
cout << num;
return 0;
}