X = list(str(input())) intX = [int(x) for x in X] intX.sort() intX.reverse() listX = list(itertools.permutations(intX, len(intX))) if len(set(listX)) <= 1: print(-1) exit() for i in range(len(X)): if listX[1][0] == 0: print(-1) exit() else: print(listX[1][i],end="")