#include <bits/stdc++.h>
using namespace std;
long long kadane(long long arr[], int l, int r) {
  long long maxs = arr[l];
  long long cm = arr[l];
  for (long long i = l + 1; i <= r; i++) {
    cm = max(arr[i], cm + arr[i]);
    maxs = max(maxs, cm);
  }
  return maxs;
}
void solve() {}
bool compare(pair<int, int> a, pair<int, int> b) {
  return abs(a.first - a.second) > abs(b.first - b.second);
}
bool isValid(int arr[501][501], int i, int j, int n, int m) {
  if ((i >= 0 || i <= n - 1) && (j >= 0 || j <= m - 1) && (arr[i][j] == 0))
    return true;
  return false;
}
void dfs(vector<vector<int>> tree, int u, vector<int> &depth,
         vector<bool> &visited, int d) {
  visited[u] = true;
  depth[u] = d;
  if (tree[u].size() == 0) return;
  for (int i = 0; i < tree[u].size(); i++) {
    if (!visited[tree[u][i]]) {
      dfs(tree, tree[u][i], depth, visited, d + 1);
    }
  }
}
bool cmp(int a, int b) { return a > b; }
char S[200004];
int main() {
  string S;
  cin >> S;
  int n = S.length();
  if (n == 0 && S[0] == '9') {
    cout << 0;
    return 0;
  }
  for (auto i = 0; i < n; i++) {
    int x = (int)(S[i] - '0');
    if (i == 0 && x == 9) {
      cout << 9;
      continue;
    }
    cout << min(x, 9 - x);
  }
  cout << "\n";
}
