#include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { string x; cin >> x; vector c(10, 0); for(int i = 0; i < (int)x.size(); i++) { c[x[i] - '0']++; } int n = 0; for(int i = 0; i < 10; i++) if(c[i]) n++; if(n == 1) { cout << -1 << endl; return 0; } n = 0; for(int i = 1; i < 10; i++) n += c[i]; if(n == 1) { cout << -1 << endl; return 0; } string ans = ""; bool b = false; for(int i = 0; i < 10; i++) { if(c[i]) { if(!b) { for(int j = 0; j < c[i] - 1; j++) ans += '0' + i; for(int j = i + 1; j < 10; j++) { if(c[j]) { ans += '0' + j; c[j]--; break; } } ans += '0' + i; b = true; } else { for(int j = 0; j < c[i]; j++) ans += '0' + i; } } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }