from itertools import permutations x = list(input()) set_x = set("".join(p) for p in permutations(x, len(x)) if p[0] != "0") if len(set_x) == 1: print(-1) else: print(sorted(list(set_x))[-2])