#include<bits/stdc++.h>

using namespace std;

string s = "";
map<char, char> mp;

int main(){
	mp['0'] = '0' ; mp['1'] = '1' ; mp['6'] = '9' ; mp['8'] = '8' ; mp['9'] = '6' ;
	cin >> s;
	for(int i = s.length() - 1 ; i >= 0 ; i --) cout << mp[s[i]];
	return 0;
}

#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fo(i,z,n) for(int i = z;i<n;i++)
#define rfo(i,z,n) for(int i = z;i >= n;i--)

#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vc vector<char>
#define vpi vector<pair<int,int> >
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvpi vector<vector<pair<int,int> > >
#define vvc vector<vector<char> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
#define int long long
#define float double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


 void __print(int x) {cerr << x;}
// void __print(long x) {cerr << x;}
// void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
// void __print(float x) {cerr << x;}
// void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int ceil(int a,int b){
    if(a%b == 0)return a/b;
    else return a/b+1;
}

int pow(int a,int b){
    if(b == 0)return 1;
    int res = pow(a,b/2);
    res = res*res;
    if(b&1)res *= a;
    return res;
}

// ordered_set s;


void solve(){
  
    string s;
    cin >> s;
    int n = s.length();
    reverse(all(s));
    for(int i = 0;i < n;i++){
        if(s[i] == '6')s[i] = '9';
        else if(s[i] == '9')s[i] = '6';
    }
    cout << s << endl;
    

    return;    
  
   
}

int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);

 

     int t = 1;
     // cin >> t;
     while(t--){
        solve();
     }






return 0;
    
    }