N=list(map(int,list(input()))) S=N for i in range(len(N)): T=N[i:] if max(T)==T[0]:continue else: S=N[:i] break else: print(''.join([str(x) for x in N])) exit() x=max(T) for i in range(len(T))[::-1]: if T[i]==x:y=i;break for i in range(len(T)): tmp=T[i:] if max(tmp)==tmp[0]:continue if T[i]!=x: o=i if y>o:T[y],T[o]=T[o],T[y] print(''.join([str(x) for x in S+T])) break