#include main(){std::string s;std::cin>>s;sort(s.rbegin(),s.rend());std::cout<<(prev_permutation(s.begin(),s.end())&&s[0]-48?s:"-1");}