#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    ifstream fi("tlptp.inp");
    ofstream fo("tlptp.out");
    string s,s1;
    int d = 0;
    int64_t t = 0;
    getline(fi,s);
    std::transform(s.begin(),s.end(),s.begin(),::toupper);
    while (s[0] == 48) s.erase(0,1);
    for (int i = s.length()-1; i >= 0; i--)
    {
        if (s[i] <= 57 && s[i] >= 48) s1 = s[i];
        else
        {
            if (s[i] == 65) s1 = "10";
            if (s[i] == 66) s1 = "11";
            if (s[i] == 67) s1 = "12";
            if (s[i] == 68) s1 = "13";
            if (s[i] == 69) s1 = "14";
            if (s[i] == 70) s1 = "15";
        }
        int tg = 0;
        istringstream c(s1);
        c >> tg;
        t += tg*pow(16,d);
        d++;
    }
    fo<<t;
    return 0;
}

