x=list(input()) if len(set(x))==1: # 999 print(-1) exit() flg=True for i in range(1,len(x)): if x[i] != "0": flg=False if flg: print(-1) exit() x.sort() now=0 for i in range(1,len(x)): if x[now] != x[i]: x[now],x[i] = x[i],x[now] break else: now=i x=list(reversed(x)) print(*x,sep="")