#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  string O;
  cin >> O;
  int l = O.length();
  vector<char> P(10);
  for(int i = 0; i < 10; ++i) P[i] = '0' + i;
  long long int m = 0, k = 1;
  for(int i = 0; i < l; ++i) k *= 10;
  string ans;
  do{
    string t;
    for(int i = 0; i < l; ++i) t += P[i];
    if(min(abs(stoll(O)-stoll(t)), k - abs(stoll(O)-stoll(t))) > m){
      m = min(abs(stoll(O)-stoll(t)), k - abs(stoll(O)-stoll(t)));
      ans = t;
    }
  }while(next_permutation(P.begin(),P.end()));
  cout << ans << endl;
  return 0;
}

