import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String inputHex = in.nextLine();
inputHex = inputHex.substring(2);
int result = 0;
for( int i = 0 ; i < inputHex.length() ; i++ ){
int position = inputHex.length() - i - 1;
int value = Integer.parseInt(alphaBetHandler(inputHex.substring(i,i+1)));
result = result + value * (int)Math.pow(16,position);
}
System.out.println(result);
}
public static String alphaBetHandler(String inputCharactor){
String result = inputCharactor;
if(inputCharactor.equals("A")){
result = "10";
} else if (inputCharactor.equals("B")) {
result = "11";
} else if (inputCharactor.equals("C")) {
result = "12";
} else if (inputCharactor.equals("D")) {
result = "13";
} else if (inputCharactor.equals("E")) {
result = "14";
} else if (inputCharactor.equals("F")) {
result = "15";
}
return result;
}
}