#include #include #include using namespace std; int main() { int N; cin >> N; string Ns = to_string(N); vector check((int)Ns.size()); check[0] = true; for (int i = 1; i < (int)Ns.size(); ++i) { if (Ns[i] < Ns[i - 1]) check[i] = true & check[i - 1]; } int maxdigit = 0; int maxidx = -1; for (int i = 0; i < (int)Ns.size(); ++i) { if (check[i]) continue; if (maxdigit <= Ns[i] - '0') { maxdigit = Ns[i] - '0'; maxidx = i; } } if (maxidx != -1) for (int i = 0; i <= maxidx; ++i) { if (Ns[i] - '0' < Ns[maxidx] - '0') { swap(Ns[i], Ns[maxidx]); break; } } cout << Ns << endl; }