#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){

    string S;

    cin >> S;

    stack<char> st;
    int si = S.size();
    rep(i,si){
        switch(S[i]){
            case '6':S[i] = '9';
            break;
            case '9':S[i] = '6';
            break;
        }
        st.push(S[i]);
    }

    rep(i,si){
       cout <<  st.top();
       st.pop();
    }
    cout << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int i;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='0')
            s[i]='0';
        else if(s[i]=='1')
            s[i]='1';
        else if(s[i]=='6')
            s[i]='9';
        else if(s[i]=='8')
            s[i]='8';
        else s[i]='6';
    }
    cout<<s<<endl;
    return 0;
}
