#include int main(){ char c; int s=0; while(1){ scanf("%c", &c); if(c=='\n') break; if(c>='0' && c<='9') c = c - '0'; else if(c>='A' && c<='F') c = c-'A'+10; else{ printf("-1\n"); return 1; } s = s*16+c; } printf("%d\n", s); return 0; }