X = list(input()) X.sort(reverse=True) for i in range(len(X) - 2, -1, -1): if X[i] != X[i + 1]: X[i], X[i + 1] = X[i + 1], X[i] break else: print(-1) exit() if X[0] == "0": print(-1) else: print(*X, sep="")