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

char hex2dec(char a)
{
    int tmp;
    if(a >= '0' && a <= '9')
    {
        tmp = a - '0';
    }
    else if(a >= 'A' && a <= 'F')
    {
        tmp = a - 'A' + 10;
    }
    else if(a >= 'a' && a <= 'f')
    {
        tmp = a - 'a' + 10;
    }
    else {
        tmp = 0;
        printf("error input\n");
    }
    //printf("tmp=%d\n", tmp);
    return tmp;
}


int main() {
    char h[100];
    int a;
    while (scanf("%s", &h[0]) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        for(int i = 2; i < strlen(h); i++)
        {
            a += (hex2dec(h[i])) << (4 * (strlen(h) -2 - i + 1)) ;
            //printf("h[%d]=%d, strlen(h)=%d, hex2dec(h[i])=%d a=%d\n", i, h[i], strlen(h), hex2dec(h[i]), a);
        }
        printf("%d\n", a);
    }
    return 0;
}