#include using namespace std; using ll = long long; int main() { string s; cin >> s; int n = s.size(); string t = s; if(count(s.begin(), s.end(), '0') == n - 1 || unique(t.begin(), t.end()) == t.begin() + 1) { cout << -1 << endl; return 0; } sort(s.begin(), s.end(), greater()); prev_permutation(s.begin(), s.end()); cout << s << endl; }