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

#define endl "\n"
#define ll long long

int main()
{
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  int l = s.size();
  for(int i=0;i<l;i++)
  {
    if(s[i]=='9')s[i] = '6';
    else if(s[i]=='6')s[i] = '9';
  }
  cout<<s<<endl;
  return 0;
}

#include <bits/stdc++.h>

int main()
{
	std::string s, t = "";
	std::string table[] = { "0", "1", "", "", "", "", "9", "", "8", "6", };

	std::cin >> s;

	for (int i = s.length() - 1; i >= 0; i--)
		t += table[s[i] - '0'];

	std::cout << t << std::endl;

	return 0;
}
