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