S=list(input()) S.sort(reverse=True) import copy s=copy.deepcopy(S) for i in range(1,len(S)): if s[-1-(i-1)] != s[-1-i]: s[-1-(i-1)],s[-1-i] = s[-1-i],s[-1-(i-1)] break if s[0]=="0": print(-1) elif S!=s: print("".join(s)) else: print(-1)