#include using namespace std; int afterMaxId[20]; int main(){ string N; cin >> N; int size = N.size(); afterMaxId[size-1] = size-1; for(int i=size-2;i>=0;i--){ int id = afterMaxId[i+1]; if(N[i] > N[id]){ id = i; } afterMaxId[i] = id; } for(int i=0;i N[i]){ swap(N[id], N[i]); break; } } cout << N << endl; return 0; }