import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            System.out.println(convertJz(s));
        }
    }
    public static Integer convertJz(String str){
        int result = 0;
        if(str==null){
            return result;
        }
        String replace = str.replace("0x", "");
        for(int i = replace.length()-1 ;i>=0;i--){
            double y = Math.pow(16, replace.length()-1-i);
            int x = replace.charAt(i);
            if(x-60>0){
                x = x - 55;
            }else{
                x = Integer.parseInt(replace.charAt(i)+"");
            }
            result += x * (int)y;
        }
        return result;
    }

}