import collections x = int(input()) x_list = list(str(x)) sorted_x = sorted(x_list, reverse=True) clc = collections.Counter(sorted_x) num_clc = len(clc.keys()) if num_clc == 1: res = -1 else: swap_index = sorted_x.index(min(sorted_x)) sorted_x[swap_index], sorted_x[swap_index - 1] = \ sorted_x[swap_index - 1], sorted_x[swap_index] if sorted_x[0] == '0': res = -1 else: res = ''.join(sorted_x) print(res)