public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
HashMap<Character,Integer> map = new HashMap<>();
map.put('0',0);
map.put('1',1);
map.put('2',2);
map.put('3',3);
map.put('4',4);
map.put('5',5);
map.put('6',6);
map.put('7',7);
map.put('8',8);
map.put('9',9);
map.put('A',10);
map.put('B',11);
map.put('C',12);
map.put('D',13);
map.put('E',14);
map.put('F',15);
while(sc.hasNext()){
long sum = 0;
String str = sc.next();
str = str.substring(2);
for(int i = str.length() - 1; i >= 0 ; i--){
Set<Map.Entry<Character,Integer>> entry = map.entrySet();
for(Map.Entry<Character,Integer> e : entry){
if(e.getKey() == str.charAt(i)){
double a = str.length()-1-i;;
double b = 16.0;
sum = sum + (long)(e.getValue() * Math.pow(b,a));
break;
}
}
}
System.out.println(sum);
}
}
}