#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, r, r1, s, s1, pos, pos1, nx = 0;
  int digits[19], index = 0;
  cin >> x;
  pos = 1;
  do {
    pos1 = pos;
    pos *= 10;
    r = x % pos;
    s = (x - r) / pos;
    r1 = r % pos1;
    s1 = (r - r1) / pos1;
    digits[index] = s1;
    index++;
  } while (s != 0);
  for (int i = index - 1; i >= 0; i--) {
    if (!(i == index - 1) || !(digits[i] == 9)) {
      if (digits[i] > 4) digits[i] = 9 - digits[i];
      nx = nx + digits[i] * pos1;
    } else {
      nx = nx + digits[i] * pos1;
    }
    pos1 /= 10;
  }
  cout << nx << endl;
  return 0;
}
