//KY80 进制转换
#include<bits/stdc++.h>
using namespace std;
int main(){
    char arr[100];
    vector<int> arr1;

    while(scanf("%s",arr) != EOF){
        string str = arr;
        int len = str.length();
        long long sum = 0;
        for( int i = 2 ; i < len;++i){
            int dig;
            if(str[i] >= '0' && str[i]<='9'){
                dig = str[i] - '0';
            }else if (str[i] >='A' && str[i]<= 'Z' ){
                dig = str[i] - 'A' +10;
            }else if(str[i]>='a' && str[i]<='z'){
                dig = str[i] - 'a' +10;
            }
            sum += dig * pow(16,len-i-1);
        }
        printf("%lld\n",sum);

    }
}