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

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  unsigned int v=s.size();
  for(unsigned int i=0;i<v;i++){
    if(s[i]=='6'){
      s[i]='9';
      continue;
    }
    if(s[i]=='9'){
      s[i]='6';
      continue;
    }
  }
  cout<<s<<endl;
  return 0;
}
#include <iostream>
#include <stdio.h>
#include <climits>
#include <string>

//martin02

using namespace std;

int main() {
	string s;
	cin >> s;
	string s2;

	for (int i = s.length() - 1; i >= 0; i--) {
		if (s.at(i) == '0') {
			s2 += '0';
		}
		else if (s.at(i) == '1') {
			s2 += '1';
		}
		else if (s.at(i) == '6') {
			s2 += '9';
		}
		else if (s.at(i) == '8') {
			s2 += '8';
		}
		else {
			s2 += '6';
		}
	}

	cout << s2 << endl;

	return 0;
}