#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; bool comp(int i, int j) { return i > j; } int main(){ string s,t; cin >> s; t = s; sort(t.begin(), t.end(),greater()); next_permutation(t.begin(), t.end(),comp); if (t == s) { cout << -1 << endl; } else { if (t[0] == '0') cout << -1 << endl; else cout << t << endl; } return 0; }