#include using namespace std; void no_927(void) { string x; cin >> x; int x_size = (int)x.size(); sort(x.begin(), x.end()); reverse(x.begin(), x.end()); if(!prev_permutation(x.begin(),x.end())){ cout << "-1" << endl; return; } if(x[0]=='0'){ cout << "-1" << endl; return; } cout << x << endl; } int main(void) { no_927(); return 0; }