#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

/*
 *	Return the numeric value represented by the hex digit c.
 */
int getval (char c) {
  switch (c) {
  case '0': case '1': case '2': case '3': case '4': 
  case '5': case '6': case '7': case '8': case '9':
    return c - '0';
  case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
    return 10 + c - 'a';
  case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
    return 10 + c - 'A';
  default:
    return 0;
  }
}


int main () {
  int c;
  int val;
  while (1) {
    c = getchar();
    val = 0;
    if (c == EOF) exit(0);
    while ((c != EOF) && (c != '\n') && isalnum(c)) {
      val = val*16+getval(c);
      c = getchar();
    }
    printf("%d\n", val);
    if (c == EOF) exit(0);
  } 
  return 0;
}

