#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    string X;
    cin >> X;
    vector<int> d(10, 0);
    int n = X.size();
    rep(i, n) {
        d[X[i] - '0']++;
    }
    string Y;
    rep(i, 10) {
        rep(j, d[9 - i]) {
            Y += to_string(9 - i);
        }
    }
    rep(i, n - 1) {
        if (Y[n - i - 2] == Y[n - i - 1]) continue;
        if (Y[n - i - 1] == '0' && i == n - 2) continue;
        rep(j, n) {
            if (j == n - i - 2) cout << Y[n - i - 1];
            else if (j == n - i - 1) cout << Y[n - i - 2];
            else cout << Y[j];
        }
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
}