#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  long long int n = atoll(s.c_str());
  long long int mn = n;
  for (int i = 0; i < s.size(); i++) {
    string k = s;
    k[i] = '9' - k[i] + '0';
    long long int t = atoll(k.c_str());
    if (i == 0 && k[i] == '0') continue;
    if (t < mn) {
      s = k;
      mn = t;
    }
  }
  cout << mn << endl;
}
