#include #define PI 3.14159265359 #define NIL -1 using namespace std; const int64_t MOD = 1e9 + 7; int main() { string X; cin >> X; string S = X; sort(S.begin(), S.end()); string R = S; reverse(R.begin(), R.end()); if (S.at(0) == S.at(S.size() - 1)) { cout << -1 << endl; return 0; } bool b = false; for (int i = R.size()-1; i > 0; i--) { if (R.at(i) != R.at(i - 1)) { char ch = R.at(i); R.at(i) = R.at(i - 1); R.at(i - 1) = ch; b = true; break; } } if (R.at(0) == '0') b = false; cout << (b ? R : "-1") << endl; }