import java.util.Scanner;
//用API=回家等通知
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String s = in.nextLine();
String tempS = s.substring(2);
//转换
int ans = new Main().change(tempS);
//十进制输出
System.out.println(ans);
}
}
public int change(String s){
int ans=0,x=0;
for(int i=s.length()-1;i>=0;i--){
char c = s.charAt(i);
if(c>='A' && c<='F'){
ans+=(c-'A'+10)*Math.pow(16,x++);
}else{
ans+=(c-'0')*Math.pow(16,x++);
}
}
return ans;
}
}