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

/*
 *	Return the numeric value represented by the hex digit c.
 */
char codes[]="0123456789abcdefABCDEF";
int  vals[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,10,11,12,13,14,15};

int getval (char c) {
  char *code = strchr(codes,c);
  int index = code ? code-codes : 0;
  return vals[index];
}


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;
}

