import java.util.; import java.io.; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = null; Map<Character,Integer> map = new HashMap<>(); char ch = '0'; for(int i = 0;i < 10;i++){ map.put(ch++,i); } char chA = 'A'; char cha = 'a'; for(int i = 0;i < 6;i++){ map.put(chA++,10+i); map.put(cha++,10+i); } while((str = in.readLine())!=null){ int len = str.length(); int number = 0; int score = 1; for(int i = len - 1;i >= 2;i--){ number += map.get(str.charAt(i))*score; score *= 16; } System.out.println(number); } } }