#yukicoder import copy X = list(input()) X = sorted(X)[::-1] XX = copy.deepcopy(X) for i in range(len(X)-1,0,-1): if XX[i] != XX[i-1]: XX[i],XX[i-1] = XX[i-1],XX[i] break if XX[0] == "0" or X == XX: print(-1) else: print(*XX,sep="")