x = int(input()) s = list(str(x)) if len(set(s)) == 1: print(-1) exit() s = [int(i) for i in s] #s.sort(reverse=True) d = {} for i in s: if i in d: d[i] += 1 else: d[i] = 1 #print(d) keys = list(d.keys()) keys.sort(reverse=True) ans = [] for k in keys: ans += [k]*d[k] last = d[k] ans[-last-1], ans[-last] = ans[-last], ans[-last-1] if ans[0] == 0: print(-1) else: print(''.join(map(str, ans)))