x = list(input()) x.sort(reverse=True) y = sorted(x, reverse=True) z_flag = False las_ind = -1 if "0" in x: while not z_flag: if x[las_ind] == "0": las_ind -= 1 else: z_flag = True x[las_ind], x[las_ind+1] = x[las_ind+1], x[las_ind] if x[0] == "0":print(-1) else:print("".join(x)) else: y[-1], y[-2] = y[-2], y[-1] if y[0] == "0" or x == y: print(-1) else:print("".join(y))