x = input() y = sorted(x, reverse=True) if y[0]==y[-1]: print(-1) else: for i in range(1, len(y)): if y[-1] != y[-1-i]: y[-1-i], y[-i] = y[-i], y[-i-1] break if y[0] == '0': print(-1) else: print(''.join(y))