#include
using namespace std;
int Count(long int x) {
int a=0, p=x;
for (;x!=0;x=x/10) {
a++;
}
x=p;
return a;
}
int Inverse(long int x) {
int b, c, e=1;
int z=0;
long int j=1;
for (int a=1; a<=Count(x); a++) {
j=j10;
}
long int o=x%j;
for (b=1; b<=Count(x); b++) {
c=x%10;
if (c>4 && b!=Count(x)) {
c=9-c;
}
if (b==Count(x) && o!=9) {
if (c>4) {
c=9-c;
}
}
int e=1;
for (int d=1; d<=b-1; d++) {
e=e10;
}
z=z+(e*c);
x=x/10;
}
return z;
}
int main() {
long int x;
cin >> x;
cout << Inverse(x);
return 0;
}