#include <algorithm>
#include <bits/stdc++.h>
using namespace std;


#define ll long long
#define rep(i, N) for(int i = 0; i < N; ++i)


void solve(std::string S){
	reverse(S.begin(), S.end());

	rep(i, S.size()){
		char w = S[i];
		if(w == '0' or w == '1' or w == '8'){
			cout << w;
			continue;
		}

		if(w == '9'){
			cout << '6';
			continue;
		}

		if(w == '6'){
			cout << '9';
			continue;
		}
	}

	cout << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
  string S;
  cin >> S;
  
  S = regex_replace(S, regex("6"), "5");
  S = regex_replace(S, regex("9"), "6");
  S = regex_replace(S, regex("5"), "9");
  string S_reversed (S.rbegin(), S.rend());
  
  cout << S_reversed << endl;
}