#include #include #include #include #include #include #include #include #include using namespace std; using int64 = long long; int main() { string s; cin >> s; string t = s; sort(t.rbegin(), t.rend()); if (all_of(t.begin()+1, t.end(), [](const char& c){return c=='0';})) { cout << -1 << endl; return 0; } prev_permutation(t.begin(), t.end()); if (t == s) { cout << "-1" << endl; } else { cout << t << endl; } }