#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  string str, ans = "";
  cin >> str;
  int n;
  for (int i = 0; i < str.length(); i++) {
    n = str[i] - '0';
    if (n >= 5) {
      if (i == 0 && n == 9)
        ans += str[i];
      else
        ans += char(9 - n + '0');
    } else
      ans += str[i];
  }
  cout << ans << "\n";
  return 0;
}
