{$apptype console}
// ACM 2009
// Problem A
// (C) Chistyakov T. S.

uses
  Classes, Math;

type
  TNumber = array of integer;

function incNumber(const s: TNumber; base: integer): TNumber;
var
  i: integer;
begin
  result := Copy(s);
  for i := High(s) downto 0 do
    if s[i] + 1 < base then begin
      Inc(result[i]);
      exit;
    end
    else
      result[i] := 0;
  SetLength(Result, Length(Result) + 1);
  for i := High(Result) downto 1 do
    Result[i] := Result[i - 1];
  Result[0] := 1;
end;

var
  fi: textfile;
  c: char;
  s, r: TNumber;
  t: string;
  minBase: integer;
  i, j: integer;
  ans: TStringList;
begin
  assignfile(fi, 'input.txt');
  reset(fi);
  i := 0;
  minBase := 2;
  while not SeekEof(fi) do begin
    read(fi, c);
    SetLength(s, i + 1);
    if c in ['0'..'9'] then
      s[i] := ord(c) - ord('0')
    else if c in ['A'..'Z'] then
      s[i] := ord(c) - ord('A') + 10
    else
      halt(1);
    minBase := Max(minBase, s[i] + 1);
    Inc(i);
  end;
  closefile(fi);

  ans := TStringList.Create;
  try
    ans.Sorted := true;
    ans.Duplicates := dupIgnore;
    for i := minBase to 36 do begin
      r := incNumber(s, i);
      SetLength(t, Length(r));
      for j := 0 to High(r) do
        if r[j] < 10 then
          t[j + 1] := Char(r[j] + Ord('0'))
        else
          t[j + 1] := Char(r[j] - 10 + Ord('A'));
      ans.Add(t);
    end;
    ans.SaveToFile('output.txt');
  finally
    ans.Free;
  end;
end.
