X = input() N = [0 for _ in range(10)] for x in X: N[int(x)] += 1 if sum([bool(n) for n in N]) == 1: print(-1) elif sum(N[1:]) == 1: print(-1) else: res = [] for i in range(10)[::-1]: res.extend([str(i)] * N[i]) for i in range(len(res) - 1)[::-1]: if res[i] != res[i + 1]: res[i], res[i + 1] = res[i + 1], res[i] break print(''.join(res))