n = [x for x in input()] max_num = max(n) for index, num in enumerate(n): target = max(n[index:]) if int(num) < int(target): lists_index = [x for x, num2 in enumerate(n) if num2 == target and x > index] replace_index = lists_index.pop() n[index], n[replace_index] = target, num print(int(''.join(n))) break else: print(int(''.join(n)))