#include <iostream>
#include <algorithm>
using namespace std;

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  for(auto& a:s){
    if (a=='6') {
      a='9';
    } else if(a=='9') {
      a='6';
    }
  }
  cout<<s<<endl;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, S;
  cin >> s;
  int n;
  n = s.size();
  
  for (int i = n - 1; -1 < i; i--){
    if (s.at(i) == '6')
      S += '9';
    if (s.at(i) == '9')
      S += '6';
    if (s.at(i) != '9' && s.at(i) != '6')
      S += s.at(i);
    if (i == 0)
      cout << S << endl;
  }
}
