#include <bits/stdc++.h>
using namespace std;

int main(){
  string s, s1; cin >> s;
  s1 = s;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0'){
      s1.at(s.size() - 1 - i) = '0';
    }
    else if (s.at(i) == '1'){
      s1.at(s.size() - 1 - i) = '1';
    }
    else if (s.at(i) == '6'){
      s1.at(s.size() - 1 - i) = '9';
    }
    else if (s.at(i) == '8'){
      s1.at(s.size() - 1 - i) = '8';
    }
    else if (s.at(i) == '9'){
      s1.at(s.size() - 1 - i) = '6';
    }
  }
  cout << s1 << endl;
}
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
const int M=1e9+7;
const int N=200005;


signed main(){
  int t1=1;
  //cin>>t1;
  while(t1--){
    string s;
    cin>>s;

    reverse(s.begin(),s.end());
    for(int i=0;i<s.length();i++){
      if(s[i]=='6') s[i]='9';
      else if(s[i]=='9') s[i]='6';
    }

    cout<<s<<endl;
  }
}
