#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    ll old = 0;
    ll tenN = 1;
    for(int i=0; i<s.size(); ++i) {
        old = old * 10 + (s[i]-'0');
        tenN *= 10;
    }
    vector<int> v={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    ll res = 0, memo = 0;
    do {
        ll t = 0;
        for(int i=0; i<s.size(); ++i) {
            t = t*10 + v[i];
        }
        ll t2 = abs(old - t);
        ll t3 = min(tenN - t2, t2);
        if(memo < t3) {
            res = t;
            memo = t3;
        }
    } while(next_permutation(v.begin(), v.end()));
    string ret;
    for(int i=0; i<s.size(); ++i) {
        tenN /= 10;
        ret += (res/tenN) + '0';
        res = res - (res/tenN)*tenN;
    }
    cout << ret << endl;
}
