from collections import Counter x = input() c = Counter(x) if len(c.keys()) == 1: print(-1) exit() ans = sorted(x, reverse=True) for i in range(len(ans)-1, -1, -1): if ans[i] != ans[i-1]: ans[i], ans[i-1] = ans[i-1], ans[i] break if ans[0] == 0: print(-1) exit() print(''.join(map(str, ans)))