#include using namespace std; typedef long long ll; int main() { string s; cin >> s; sort(s.begin(), s.end()); int st = 0; while (s[st + 1] == s[0]) st++; int pos = -1; for (int i = 1; i < s.size(); ++i) { if (s[i] != s[st]) { pos = i; break; } } if (pos == -1) { puts("-1"); return 0; } swap(s[st], s[pos]); reverse(s.begin(), s.end()); if (s[0] == '0') { puts("-1"); } else { cout << s << '\n'; } return 0; }