#include <iostream>
using namespace std;

int main()
{
    string hex;
    while (cin >> hex)
    {
        hex = hex.substr(2);
        long long res = 0;
        for (int i = 0; i < hex.size(); ++i)
        {
            int n;
            if (hex[i] >= 'A' && hex[i] <= 'F')
                n = hex[i] - 'A' + 10;
            else
                n = hex[i] - '0';
            res = res * 16 + n;
        }
        cout << res << endl;
    }
    return 0;
}