X = input() t = sorted(X, reverse=True) Y1 = ''.join(t) a, b = t[-2], t[-1] t[-2], t[-1] = b, a Y2 = ''.join(t) if Y1 == Y2 or Y2[0] == '0': print(-1) else: print(Y2)