#include <bits/stdc++.h>
using namespace std;
int main() {
  long long number;
  int arr[19]{1};
  long long answer = 0;
  cin >> number;
  int size = 0;
  answer = number;
  while (number) {
    size++;
    number /= 10;
  }
  number = answer;
  for (int i = 0; i < size; i++) {
    int temp = number % 10;
    number /= 10;
    arr[size - i - 1] = temp;
  }
  for (int i = 1; i < size; i++) {
    if (arr[i] > 9 - arr[i]) {
      bool notzero = false;
      for (int j = 0; j < i; j++) {
        if (arr[j] != 0) notzero = true;
      }
      if (notzero) arr[i] = 9 - arr[i];
    }
  }
  if (arr[0] != 9 && arr[0] > 9 - arr[0]) {
    arr[0] = 9 - arr[0];
  }
  answer = 0;
  for (int i = 0; i < size; i++) {
    answer *= 10;
    answer += arr[i];
  }
  cout << answer << endl;
  return 0;
}
