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

int main() {
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='6') s[i]='9';
		else if(s[i]=='9') s[i]='6';
	}
	cout<<s<<"\n";
	return 0;
}
#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long t{1}, f{1};
    for(unsigned long i{0}; i < N; ++i)if([]{string s;cin >> s;return s;}()[0] == 'O'){
        (t *= 2) += f;
    }else{
        (f *= 2) += t;
    }
    cout << t << endl;
    return 0;
}
