#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;
template<class T> using heapq = priority_queue<T,vector<T>,greater<T>>;
template<class T> bool chmax(T &a,const T b) {if (a<b) {a=b;return true;} else return false;} 
template<class T> bool chmin(T &a,const T b) {if (a>b) {a=b;return true;} else return false;} 
#define rep(i,n) for(int i=0; i<(n); i++)
#define srep(i,a,b) for(int i=(a); i<(b); i++)
#define rrep(i,n) for(int i=(n)-1;i>=0; i--)
#define srrep(i,a,b) for(int i=(b)-1; i>=(a); i--)
int main(){
  string s; cin >> s;
  for(char &c:s){
  	if (c=='6') c='9';
    else if (c=='9') c='6';
  }
  reverse(s.begin(),s.end());
  cout << s << endl;
}
#include <iostream>
#include <cstring>
using namespace std;


int main()
{
	string str,s;
	cin>>str;
	for(int i=str.size()-1;i>=0;i--)
	{
		if(str[i]=='0')	cout<<"0";
		if(str[i]=='6')	cout<<"9";
		if(str[i]=='8')	cout<<"8";
		if(str[i]=='9')	cout<<"6";
		if(str[i]=='1')	cout<<"1";
	}
	return 0;
}