from fractions import gcd from heapq import* import math from collections import defaultdict, Counter import sys sys.setrecursionlimit(10 ** 7) MOD = 10 ** 9 + 7 def main(): n = int(input()) sn = list(str(n)) change = -1 for i in range(1, len(sn)): base = int(sn[i-1]) for j in range(i, len(sn)): if int(sn[j]) > base: change = j base = int(sn[i]) if change != -1: break if change == -1: print(n) exit() sn[i-1], sn[change] = sn[change], sn[i-1] print(max(n, int("".join(map(str, sn))))) if __name__ == '__main__': main()