x = list(input()) if len(x)==1: print(-1) else: l = sorted(x,reverse=True) m = l[0:-2] + [l[-1],l[-2]] if int(m[0]) !=0 and l!=m: print(int(''.join(m)) ) else: print(-1)