#include <bits/stdc++.h>
int main() {
  char str[20], *ptr;
  scanf("%s", str);
  ptr = str;
  for (ptr++; *ptr; ptr++) {
    if (*ptr > '4') *ptr = '9' - (*ptr - '0');
  }
  ptr = str;
  if (str[0] != '9' && str[0] > '4') str[0] = '9' - (str[0] - '0');
  while (*ptr == '0') ptr++;
  if (*ptr == 0)
    printf("9\n");
  else
    printf("%s\n", ptr);
  return 0;
}
