#include using namespace std; typedef long long ll; const double PI = acos(-1); const ll MOD = 1000000007; int main() { string X; cin >> X; int N = X.size(); sort(X.begin(),X.end()); reverse(X.begin(),X.end()); bool can = false; for (int i = 1; i < N; i++) { if (X[N-i-1] != X[N-i]) { can = true; swap(X[N-i],X[N-i-1]); break; } } if (X[0] == '0') can = false; if (can) cout << X << endl; else cout << -1 << endl; }