X = input() l = list(map(int,list(X))) s = set(l) N = len(l) import sys if len(s) == 1: print(-1) exit() l.sort(reverse = True) u = N - 1 while l[u] == l[-1]: u -= 1 l[u],l[-1] = l[-1],l[u] if l[0] == 0: print(-1) exit() for i in l: print(i,end = "") print()