var n, i, j, z, curdiv, lead, brzn : longint;
    s : string;
    f : text;

procedure dodaj (w : longint);
var map : array[0..16] of boolean;
    i, j : integer;
label van;
begin
  fillchar (map[0], 16, False);

  for i:=1 to length (s) do
    if s[i]<'A' then map[ord(s[i])-48]:=True
                else map[ord(s[i])-55]:=True;

  i:=0;
  for j:=15 downto 0 do
      if not map[j] then begin inc (i); if i>w then goto van; end;

  van:

  if j<10 then s:=s+chr(j+48)
          else s:=s+chr(j+55);
end;

begin
  assign (f, 'HEX.IN'); reset (f);
  read (f, n);
  close (f);

  curdiv:=32432400; lead:=15; brzn:=9;

  {n:=0; j:=curdiv;
  i:=9; while j>0 do begin n:=n+15*j; j:=j div i; inc (i); end;
  n:=brkomb-n;
  for i:=9 to 16 do
      begin
      inc (n, 15*j);
      j:=j div i;
      end;}

  dec (n, 1);
  repeat;
    z:=n div curdiv;
    if z>14 then
       begin
       n:=n-15*curdiv;
       curdiv:=curdiv div brzn;
       inc (brzn);
       end
       else
       begin
       dodaj (z);
       n:=n-z*curdiv;
       curdiv:=curdiv div lead;
       dec (lead);
       end;
  until lead<brzn;

  dodaj (n);

  if s[1]='0' then delete (s, 1, 1);

  assign (f, 'HEX.OUT'); rewrite (f);
  write (f, s);
  close (f);
end.













