#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct Edge
{
  ll to;
  ll weight;
  Edge(ll t, ll w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  for (auto &it : S) {
    if (it == '6')
      it = '9';
    else if (it == '9')
      it = '6';
  }
  cout << S << endl;
  return 0;
}

#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define gcd(a,b) __gcd(a,b)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) (int)a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define IT iterator
#define SET setprecision
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
#define mod1 1000000007
#define mod2 998244353
#define infmod 9223372036854775783
#define tc int t;cin>>t;while(t--)solve();
#define over(x) {cout<<x<<endl;return;}
#define intsz(x) (int)sz(to_string(x))
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	string s;
	int d[]={0,1,0,0,0,0,9,0,8,6};
	cin>>s;
	REP_sz(i,s){
		s[i]='0'+d[s[i]-'0'];
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
    return 0;
}
