#include <bits/stdc++.h>

using namespace std;

#define ll long long

typedef pair<int, int> pii;
typedef pair<int, char> pic;

const int N = 82;
int mod = 998244353;

int n, m, a[N];

int main() {
    string s;
    cin >> s;
    map<int, int> ma;
    ma[1] = 1, ma[6] = 9;
    ma[9] = 6, ma[8] = 8;
    ma[0] = 0;
    for(int i = s.length() - 1; ~i; i --) {
        cout << ma[s[i] - '0'];
    }
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cctype>
#include <cmath>
#include<deque>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;


#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,begin,end) for(int i = begin; i < end; i++)
#define all(c) c.begin(), c.end()
#define ll long long
#define INF 2e9
#define INFLL 9223372036854775807
#define cout(n) cout << fixed << setprecision(n)

int main() {
	string s;
	cin >> s;
	reverse(all(s));
	string news;
	rep(i, s.length()) {
		if (s[i] == '6') news += '9';
		else if (s[i] == '9')news += '6';
		else news += s[i];
	}
	cout << news << endl;
}