Program btd;
var s:string;
    d,i, c:integer;
Begin
 readln(s);
 d:=0;
 for i:=1 to length(s) do
  Begin
   {tohle by byla 2kova soustava
    if s[i]='0' then d:=d*2+0
               else if s[i]='1' then d:=d*2+1;
    tohle je 13kova:}
   case s[i] of
   '0': c := 0;
   '1': c := 1;
   '2': c := 2;
   '3': c := 3;
   '4': c := 4;
   '5': c := 5;
   '6': c := 6;
   '7': c := 7;
   '8': c := 8;
   '9': c := 9;
   'a': c := 10;
   'b': c := 11;
   'c': c := 12;
   else begin;
        writeln('ERRORRORRR');
        exit;
        end;
   end;

   d := d * 13 + c;

  End;
 writeln(d);
End.
