#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
#define pb push_back
#define nline "\n"
#define gcd(a,b) (__gcd(a,b))
#define lcm(a,b) ((a*b)/gcd(a,b))
vector<ll> soe(ll n) {ll *arr = new ll[n + 1]; vector<ll>ans; for (ll i = 0; i <= n; i++) {arr[i] = 1;} arr[0] = 0; arr[1] = 0; for (ll i = 2; i <= sqrt(n); i++) {if (arr[i] == 1) {for (ll j = 2; i * j <= n; j++) {arr[i * j] = 0;}}} for (ll i = 0; i <= n; i++) {if (arr[i] == 1)ans.push_back(i);} return ans;}

const ll mod = 1e9 + 7;
/* ncr = n-1cr-1+ n-1cr  */

/******************************************************************/

ll fpow(ll a, ll g) {
	ll ag = 1;
	while (g) {
		if (g & 1) ag = (ag * a) % mod;
		a = (a * a) % mod;
		g >>= 1;
	}
	return ag;
}

void solve() {
	string s;
	cin >> s;

	for (int i = s.length() - 1; i >= 0; i--) {
		if ((s[i] - '0') == 6) {
			cout << '9';
		}
		else if ((s[i] - '0') == 9) {
			cout << '6';
		}
		else {
			cout << s[i];
		}
	}
	cout << nline;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	// int test;
	// cin >> test;
	// while(test--){
	solve();
	// }
}
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  string S;
  cin >> S;
  int num = S.size();
  for(int i = 0 ;i < num ;i++){
    if(S.at(i) == '6'){
      S.at(i) = '9';
    }
     else if(S.at(i) == '9'){
      S.at(i) = '6';
    }
  }
   string S_reverse (S.rbegin(), S.rend());
    cout << S_reverse << endl;
}