#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;

char process(char c) {
  if (c == '6') {
    return '9';
  }
  if (c == '9') {
    return '6';
  }
  return c;
}

int main() {
  string s;
  cin >> s;
  reverse(all(s));
  for (char c : s) {
    cout << process(c);
  }
  cout << endl;
}
//............Created by:- Arth Raj...........................//
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <climits>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<sstream>
#define ll long long int
#define pll pair<long long int,long long int>
#define pb push_back
#define mp make_pair
#define vi vector<long long int>
#define vii vector<pair<long long int,long long int>>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lp(i,a,b) for(long long int i=a;i<b;i++)
#define rlp(i,a,b) for(long long int i=b;i>=a;i--)
#define ld long double
#define tl tuple<ll,ll,ll>
#define all(x) (x).begin(),(x).end()
#define bs(x,b) binary_search(all(x),b)
#define vip vector<pair<long long int,pair<long long int,long long int>>>
#define pip pair<long long int,pair<long long int,long long int>>
#define INF 1e18
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;}
ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;}
int main()
{
	string s;
	cin >> s;
	string ans = "";
	rlp(i, 0, s.length() - 1)
	{
		if (s[i] == '9')
		{
			ans += '6';
		}
		if (s[i] == '8')
		{
			ans += '8';
		}
		if (s[i] == '6')
		{
			ans += '9';
		}
		if (s[i] == '1')
		{
			ans += '1';
		}
		if (s[i] == '0')
		{
			ans += '0';
		}
	}
	cout << ans << endl;
}