#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;

const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i] == '6') s[i] = '9';
        else if(s[i] == '9') s[i] = '6';
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    string s;
    cin >> s;
    string ans;
    REPR(i, s.size()){
        if(s[i] == '0'){
            ans += "0";
        }
        if(s[i] == '1'){
            ans += "1";
        }
        if(s[i] == '6'){
            ans += "9";
        }
        if(s[i] == '8'){
            ans += "8";
        }
        if(s[i] == '9'){
            ans += "6";
        }
    }
    println(ans);
    return 0;
}