/*
 * M进制转换成十进制数
 */
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int CharToInt(char target){
    if('0'<=target&&target<='9'){
        return target-'0';
    }else{
        return target - 'A' + 10;
    }
}

void Convert(string str,int x){
    int number = 0,p=1;
    int len = str.size();
    for(int i = len-1;i>=0;i--){
        number = number + CharToInt(str[i])*p;
        p=p*x;
    }
    printf("%d\n",number);
}
int main(){
    string str;
    while(cin >> str){
        str=str.substr(2);
        Convert(str,16);
    }
    return 0;
}