#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(int i=0;i<n;i++)
#define fos(i,n) for(ll i=0,i<n;i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loops(i,a,b) for (ll i = a; i < b; i++)

void solve(){
    string s;
    cin>>s;

    reverse(s.begin(),s.end());

    loop(i,0,s.size()){
        if(s[i]=='6'){
            s[i]='9';
        }else if(s[i]=='9'){
            s[i]='6';
        }
    }

    cout<<s<<"\n";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

    solve();

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

int main()
{


        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        //scanf("%lld",&n);

        cin>>str; sz=str.size();  char ch; reverse(str.begin(),str.end());

        for(i=0;i<sz;i++)
        {
            ch=str[i];

            if(ch=='6')ch='9';
            else if(ch=='9')ch='6';

            cout<<ch;
        }

        cout<<endl;




















   return 0;


}

