#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); i++)
using ll = long long;
using P = pair<ll, ll>;
template<class T> 
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}
template<class T> 
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}
// struct Edge { ll to; ll cost; Edge(ll t, ll c) { to = t; cost = c;} };
// using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<ll>>;
// priority_queue<P, vector<P>, greater<P>> q;

const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const double PI = acos(-1);



int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string t = "";
    for (ll i = 0; i < s.size(); i++) {
        if (s[i] == '6') t = t + '9';
        else if (s[i] == '9') t = t + '6';
        else t = t + s[i];
    }
    cout << t << endl;
    return 0;
} 

//小数点の出力
//cout << fixed << std::setprecision(15) << ans << endl;
#include <bits/stdc++.h>//For vectors,pairs
using namespace std;

#define ll long long
#define rep(i,j,n)  for(int i=j;i<n;i++)
#define _rep(i,n) for(int i=n;i>=0;i--)

void solve();

void cp(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
    freopen("output.txt", "w", stdout);
    #endif
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // cp();
    int t=1;//cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }

   // cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}
void solve(){
    string s;
    cin>>s;
    ll n = s.size();
    rep(i,0,n){
        if(s[i]=='6'){
            s[i] = '9';
            continue;
        }
        if(s[i]=='9'){
            s[i] = '6';
        }
    }
    _rep(i,n-1){
        cout<<s[i];
    }
    return;
}
