#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    for(int i = (int)s.length() - 1;  i >= 0; i--)  {
        if(s[i] == '6') {
            cout << "9";
        }
        else if(s[i] == '9')        {
            cout << "6";
        }
        else    {
            cout << s[i];
        }
    }
    
}

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

int main(){
 string a,b;
 char c;
 b = "";
 a = "";
 cin >> a;
 int d = a.size();
 for(int i = 0;i<d;i++){
 c = a.at(i);
 if(c == '0'){b += '0';}
 if(c == '1'){b += '1';}
 if(c == '6'){b += '9';}
 if(c == '8'){b += '8';}
 if(c == '9'){b += '6';}
   
 
 
 
 
 
 }
  for(int i =0; i<d; i++){
  cout << b.at(d-1-i);
  
  
  
  
  
  }
cout << endl;

}