#include <iostream>
#include<math.h>
using namespace std;

int main() {
    string s;
    cin>>s;
    int length = s.size();
    int num = 0;
    int time = 0;
    for(int i=length-1;i>1;i--)
    {
        if(s[i]>64)
        {
            //num = num +(s[i]-55)*pow(16,time++);
            num = num + (s[i]-'A'+10)*pow(16,time++);
        }   
        else
        {
            //num = num + (s[i]-48)*pow(16,time++);
            num = num + (s[i]-'0')*pow(16,time++);
        }
    }
    cout<<num;
}