#include <iostream>
#include "stack"
#include "cmath"
using namespace std;
int charToInt(char c) {
    if (c <= '9' && c >= '0')return c - '0';
    else if (c >= 'A' && c <= 'F')return c - 'A' + 10;
    else return c - 'a' + 10;
}
int main() {
    string a;
    while (cin >> a ) { // 注意 while 处理多个 case
        // cout <<  b << endl;
        long long ans=0;
        for (int i = a.size() - 1; i >= 2; i--) {
            ans += charToInt(a[i]) * pow(16, a.size() - 1 - i);
        }
        cout<<ans<<endl;
    }
}
// 64 位输出请用 printf("%lld")