#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Erep(i,n) for(int i = 0; i <= (n); ++i)
#define repS(i,s,n) for(int i = s; i < (n); ++i)
#define ErepS(i,s,n) for(int i = s; i <= (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) printf("%lld %s", a, "\n")
#define OutputS(a) printf("%s %s", a, "\n")

typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vst;

const ll INF = 0x1fffffffffffffff;
const ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

string s;

void input(){
    cin >> s;
}

void solve(){
    string ans = "";
    rep(i, s.size()){
        if(s[i] == '6'){
            ans.push_back('9');
        }else if(s[i] == '9'){
            ans.push_back('6');
        }else{
            ans.push_back(s[i]);
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define MOD 1000000007
#define pi 3.1415926536
/* BAAP BAAP HOTA HAI
   AUTHOR- Devansh Nandasana*/
void adde(vector<ll> adj[],ll u,ll v)
{
  adj[u].pb(v);
  adj[v].pb(u);
}
ll modInverse(ll a, ll m)
{
    ll m0=m;
    ll y=0,x=1;
    if(m==1)
      return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m,a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0)
      x+=m0;
    return x;
}
void BFS(vector<ll> adj[],ll bfs[],ll s,ll n)
{
    bool *visited = new bool[n+1];
    for(ll i=0;i<n+1;i++)
        visited[i] = false;
    list<ll> queue;
    visited[s] = true;
    bfs[s]=0;
    queue.push_back(s);
    vector<ll>::iterator i;
    while(!queue.empty())
    {
        s=queue.front();
        queue.pop_front();
        for(i=adj[s].begin();i!=adj[s].end();++i)
        {
            if(!visited[*i])
            {
                visited[*i] = true;
                bfs[*i]=bfs[s]+1;
                queue.push_back(*i);
            }
        }
    }
}
ll nCrModp(ll n,ll r,ll p)
{
    if (r > n - r)
        r = n - r;
    ll C[r + 1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j - 1]) % p;
    }
    return C[r];
}
ll find_center(ll n,vector<ll> adj[])
{
  queue<ll> q;
  bool vis[n+1];
  ll cnt[n+1];
  for(ll i=1;i<=n;i++)
  {
    vis[i]=false;
    cnt[i]=adj[i].size();
    if(cnt[i]==1)
    q.push(i);
  }
  while(q.size()>1)
  {
    ll cur=q.front();
    vis[cur]=true;
    q.pop();
    for(ll i=0;i<adj[cur].size();i++)
    {
      if(!vis[adj[cur][i]])
      {
        cnt[adj[cur][i]]--;
        if(cnt[adj[cur][i]]==1)
        q.push(adj[cur][i]);
      }
    }
  }
  return q.front();
}
int main()
{
  #ifndef ONLINE_JUDGE
  	freopen("/home/devansh/Desktop/temp/input.txt", "r", stdin);
  	freopen("/home/devansh/Desktop/temp/output.txt", "w", stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin>>s;
  reverse(&s[0],&s[s.length()]);
  for(ll i=0;i<s.length();i++)
  {
    if(s[i]=='6')
      s[i]='9';
    else if(s[i]=='9')
      s[i]='6';
  }
  cout<<s<<"\n";
}
