#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, flag;
  cin >> n;
  std::vector<int> v;
  while (n != 0) {
    x = n % 10;
    v.push_back(x);
    n = n / 10;
  }
  for (int i = 0; i < v.size(); i++) {
    if (i == v.size() - 1) {
      if (v[i] == 9) {
        v[i] = 9;
      } else {
        if (v[i] >= 5) v[i] = 9 - v[i];
      }
    }
    if (v[i] >= 5 && i != v.size() - 1) {
      v[i] = 9 - v[i];
    }
  }
  for (int i = v.size() - 1; i >= 0; i--) {
    cout << v[i];
  }
  return 0;
}
