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

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  for(int i=0; i<s.size(); i++){
    if(s.at(i) == '6')s.at(i)='9';
    else if(s.at(i) == '9')s.at(i)='6';
  }
  cout<<s<<endl;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define int long long
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define endl "\n"
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MAX = 2e5 + 5;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll power(ll x, ll n) {
    if (!n) {
        return 1;
    }
    return (n & 1 ? mul(x, power(mul(x, x), n / 2)) : power(mul(x, x), n / 2));
}

void solve() {
    string s;
    cin >> s;
    reverse(all(s));
    for (auto ch : s) {
        cout << (ch == '6' ? '9' : ch == '9' ? '6' : ch);
    }
}

signed main() {
    fastio;

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}