/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;
template<class T>void show(vector<T> &a) {cerr << "[ "; for (int ij = 0; ij < (int)a.size(); ij++) {cerr << a[ij] << " ";} cerr << "]\n";}
template<class T>void show(T a) {cerr << a << endl;}
template<typename... T>void show(T... args) {((cerr << args << ' '), ...); cerr << endl;}

void solve() {
	int i, j;

	map<int, int> mp;

	mp[0] = 0;
	mp[1] = 1;
	mp[6] = 9;
	mp[8] = 8;
	mp[9] = 6;


	string s;
	cin >> s;

	for (int i = s.size() - 1; i >= 0; i--) {
		int n = s[i] - '0';
		cout << mp[n];
	}
	cout << endl;

}


int32_t main(int32_t argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int T = 1;
	// cin >> T;
	while (T--) {
		solve();
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n ;
    cout << n - 1 << endl;
    return 0;
}
