X = list(input()) X.sort(reverse=True) X_changed = X[-2:]+X[-1]+X[-2] if X_changed[0] == "0": print(-1) elif int("".join(X_changed)) == int("".join(X)): print(-1) else: print(X_changed)