#include #include #include #include #include #include #include #include #include using namespace std; using vi = vector; using vii = vector; using vs = vector; using pii = pair; #define rep(i,n) for(int i=0;i; using Graph = vii; const ll MOD = 998244353; int main() { string x, t; cin >> x; t = x; vsort(x); vsort(t); ll n = t.size(); if (t[0] == t[n - 1] || (n == 2 && t[0] == 0)) { cout << -1 << endl; return 0; } t[0] = x[1]; t[1] = x[0]; ll ans = 0; rep(i, n) { int k = t[i] - '0'; ans += k * pow(10.0, i); } cout << ans << endl; return 0; }