#include using namespace std; int main() { string S; cin >> S; int N = S.size(); vector n( N ); for( int i = 0; i < N; i++ ) { n[i] = S[i] - '0'; } sort( n.begin(), n.end(), greater() ); int flag = 0; int f = n[N - 1]; int si = -1; for( int i = N - 2; i >= 0; i-- ) { if( n[i] > f ) { si = i + 1; break; } } if( si > 0 && !( si - 1 == 0 && f == 0 ) ) { n[si] = n[si - 1]; n[si - 1] = f; flag = 1; } if( flag == 0 ) cout << -1 << endl; else { for( int i = 0; i < N; i++ ) { char c = (char)(n[i] + '0'); cout << c; } cout << endl; } }