N = int(input()) ls = [-1] * 10 rs = [-1] * 10 for i, d in enumerate(map(int, str(N))): if ls[d] == -1: ls[d] = i rs[d] = i cands = [] for i in range(1, 10): # 入れ替え要素(左) if ls[i] == -1: continue for j in reversed(range(i+1, 10)): # 入れ替え要素(右) if rs[j] == -1: continue if ls[i] >= rs[j]: continue # 入れ替えると小さくなる # 左: 位置がより左を優先 # 右: 値がより大きいのを優先 cands.append([(ls[i], i), (-j, rs[j])]) if not cands: print(N) exit() a, b = min(cands) s = list(str(N)) ai, bi = a[0], b[1] s[ai], s[bi] = s[bi], s[ai] ans = ''.join(s) print(ans)