#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int value(int bite);
string getTemp(string data);
long long getValue(string data);
int main(int argc,char** argv){
string data = "";
cin >> data;
cout << getValue(getTemp(data));
return 0;
}
int value(int bite){
bite--;
int resault = 1;
while(bite){
resault = resault * 16;
bite--;
}
return resault;
}
string getTemp(string data){
int length = data.length();
string resault = "";
for(int i = 0;i < 8 - length;i++){
resault = resault + "0";
}
for(int i = 8 - length;i < 8;i++){
resault = resault + data[i + length - 8];
}
return resault;
}
long long getValue(string data){
long long resault = 0;
for(int i = 0;i < 8;i++){
char temp = data[i];
long long value_temp = 0;
switch(temp){
case '0':
value_temp = 0;
break;
case '1':
value_temp = 1;
break;
case '2':
value_temp = 2;
break;
case '3':
value_temp = 3;
break;
case '4':
value_temp = 4;
break;
case '5':
value_temp = 5;
break;
case '6':
value_temp = 6;
break;
case '7':
value_temp = 7;
break;
case '8':
value_temp = 8;
break;
case '9':
value_temp = 9;
break;
case 'A':
value_temp = 10;
break;
case 'B':
value_temp = 11;
break;
case 'C':
value_temp = 12;
break;
case 'D':
value_temp = 13;
break;
case 'E':
value_temp = 14;
break;
case 'F':
value_temp = 15;
break;
default:
value_temp = 0;
break;
}
resault = resault + value_temp * value(8 - i);
}
return resault;
}