import collections x = int(input()) x_list = list(str(x)) x_list = [int(e) for e in x_list] sorted_x = sorted(x_list, reverse=True) if len(sorted_x) == 2: if sorted_x[1] == 0 or sorted_x[0] == sorted_x[1]: res = -1 else: res = int(str(sorted_x[1]) + str(sorted_x[0])) elif len(sorted_x) > 2: sorted_x_clc = collections.Counter(sorted_x) if len(sorted_x_clc.keys()) == 1: res = -1 else: sorted_x_clc_back = collections.Counter(sorted_x[1:]) if len(sorted_x_clc_back.keys()) == 1: sorted_x[0], sorted_x[1] \ = sorted_x[1], sorted_x[0] else: last_index_max = \ (len(sorted_x) - 1) - sorted(sorted_x[1:]).index(max(sorted_x[1:])) sorted_x[last_index_max], sorted_x[last_index_max + 1] = \ sorted_x[last_index_max + 1], sorted_x[last_index_max] res = ''.join([str(e) for e in sorted_x]) print(res)