MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): x = input() cnt = [0] * 10 num = '0123456789' for i in x: for j in range(10): if num[j] == i: cnt[j] += 1 break a,b = -1,-1 for i in range(1,10): if cnt[i] > 0: if a < 0: a = i else: b = i break if b < 0: print(-1) return ans = [] for i in range(10): if i == a: ans.append(num[b] + num[a] * (cnt[a] - 1)) elif i == b: ans.append(num[b] * (cnt[b] - 1) + num[a]) else: ans.append(num[i] * cnt[i]) print(''.join(ans[::-1])) if __name__ =='__main__': main()