X = input() L = [0]*len(X) for i in range(len(X)): L[i] = X[i] L.sort(reverse=True) if L[0] == L[-1]: print(-1) else: for i in range(len(L)-1, 0, -1): if L[i] != L[i-1]: t = L[i] L[i] = L[i-1] L[i-1] = t break if L[0] != "0": print("".join(L)) else: print(-1)