import sys sys.set_int_max_str_digits(10 ** 9) x = input() lst = [i for i in x] lst.sort(reverse = True) if lst[0] == lst[-1] or lst[1] == "0": print(-1) exit() l = len(lst) for i in range(l - 1, 0, -1): if lst[i] == lst[i - 1]: continue else: lst[i], lst[i - 1] = lst[i - 1], lst[i] break print(int("".join(lst)))