#include<iostream>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
int sum=0;
int i=2;
while(s[i]!='\0')
{
int d=0;
if(s[i]=='A')d=10;
else if(s[i]=='B')d=11;
else if(s[i]=='C')d=12;
else if(s[i]=='D')d=13;
else if(s[i]=='E')d=14;
else if(s[i]=='F')d=15;
else{
d=s[i]-'0';
}
sum=sum*16;
sum+=d;
i++;
}
cout<<sum<<endl;
}
return 0;
}