#include<bits/stdc++.h>
using namespace std;
int main(){
    string n;
    long long k=0,t=1;
    cin>>n;
    for(int i=n.size()-1;i>=0;i--){
        if(n[i]>='A'&&n[i]<='F'){
            k=k+(n[i]-55)*t;
        }
        else{
            k=k+(n[i]-48)*t;    
        }
        t=t*16;
    }
    cout<<k;
    return 0;
}
/**************************************************************
	Problem: 1292
	User: lijinkai
	Language: C++
	Result: Accepted
	Time:10 ms
	Memory:2076 kb
****************************************************************/