#include #define rep(i,n) for(int i=0;i> x; map mp; rep(i,x.size()){ mp[x[i]] ++; } if(mp.size() == 1){ cout << -1 << endl; return 0; } if(mp.size() == 2 && mp.find('0') != mp.end()){ if(mp['0'] == x.size()-1){ cout << -1 << endl; return 0; } } bool fi = true,se = false ; char f,s; for(auto p:mp){ if(fi){ f= p.first;fi = false;se = true;} else if(se){s = p.first;break;} } mp[s] --; mp[f] --; string ans = ""; for(auto p:mp){ rep(i,p.second){ ans += p.first ; } if(p.first == f) {ans += s; ans += f;} } reverse(ans.begin(),ans.end()); cout << ans << endl; return 0; }