#include #include #include #include using namespace std; int main(void) { string s; cin >> s; vector num(s.size()); set st; for (int i = 0; i < s.size(); ++i) { num[i] = s[i] - '0'; st.insert(s[i] - '0'); } sort(num.begin(), num.end(), greater()); bool ok = true; if (st.size() == 1) ok = false; for (int i = s.size() - 1; i >= 1; --i) { if (i != 1 || num[i] != 0) { if (num[i - 1] != num[i]) { swap(num[i - 1], num[i]); break; } } if (i == 1) ok = false; } if (!ok) cout << -1 << endl; else { for (auto x : num) cout << x; cout << endl; } return 0; }