#include <iostream>
#include <string>
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie()
using namespace std;
signed main(){
	//fio;
	map<int,int>mp;
	mp[0] = 0;
	mp[1] = 1;
	mp[9]= 6;
	mp[6] = 9;
	mp[8] = 8;
	string s;
	cin >> s;
	reverse(s.begin(),s.end());
	for(int i = 0;i<s.size();i++){
		cout << mp[s[i] - '0'];
	}
	return 0;
}
// Created by ...Rahul Chandra
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

ll n;

inline void read() {    
    cin >> n;
}


inline void solve() {    


}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a,b,c,d,e,f,g,rahul=0;
    string s;

    cin>>s;

    for (int i = 0; i < s.length(); ++i)
    {
        /* code */
        if (s[i]=='6')
        {
            s[i]='9';           /* code */
        }
        else if(s[i]=='9'){
            s[i]='6';
        }
        else
            continue;
    
    }
    int n=s.length()-1;
    for (int i = 0; i <n; ++i)
    {
        /* code */
      swap(s[i],s[n--]);

    }
    cout<<s;
   return 0;
}