import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
int mul=1;
int rnum=0;
while(num!=0)
{ int rev;
int rem=num%10;
if(num/10==0)
{
if(rem==9 || rem<=4)
{
rev=rem;
}
else
{
rev=9-rem;
}
}
else
{
if(rem<=4)
{
rev=rem;
}
else
{
rev=9-rem;
}
}
rnum=rnum+rev*mul;
mul=mul*10;
num=num/10;
}
System.out.print(rnum);
}
}