import itertools x = list(input()) s = itertools.permutations(x) t = list(set(s)) t.sort(reverse=True) if len(t) == 1: print(-1) elif t[1][0] == "0": print(-1) else: print("".join(t[1]))