X = input() l = list(X) f = 0 ll = list(map(int,l)) ll.sort() # ll.reverse() for i in range(len(l)): if ll[0] != ll[i]: ll[0],ll[i] = ll[i], ll[0] break else: f = 1 if f == 0: ll.reverse() ans = "".join(map(str,ll)) if len(ans) == len(str(int(ans))): print(ans) else: print(-1) else: print(-1)