import collections X = list(input()) C = collections.Counter(X) if len(C)==1: print(-1) exit() cnt = 0 for k,v in C.items(): if k!='0': cnt+=v if cnt==1: print(-1) exit() for i in range(0,10): for j in range(i+1,10): if C[str(i)] and C[str(j)]: ans = '' for k in reversed(range(10)): ans+=str(k)*(C[str(k)]-int(k==j)) if k==i: ans+=str(j) print(ans) exit()