import java.util.*;
import java.io.*;
import java.math.*;

public class test {

static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
	return Long.parseLong(next());
    }

}

 static class Task {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
  		while(testNumber-->0) {
			Long num = in.nextLong();
			char[] n = num.toString().toCharArray();
			int len = n.length;
			for(int i=0;i<len;++i) {
				int ch = n[i];
				int ch1 = ('9'-n[i])+48;
				//out.println(" ch = "+ch+" ch1 = "+ch1);
				if(i==0) {
					if(ch1!=48)
						n[i] = (char) Math.min(ch,ch1);
				}
				else
					n[i] = (char) Math.min(ch,ch1);

			}
			out.println(n);

    		}
	}

}

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int test  = 1;
        solver.solve(test, in, out);
        out.close();
    }

}

import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Main{

	static double p;

	static long n,k;
	static String S,S1,str;
	static BigInteger b;
	static char ch;

	static String [] a = {"a","b","c","d","e","f","g","h","j","k","l","m","n","o","p","q","r","s","t","u","v",
		"w","x","y","z","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L"};

	static StringBuilder Sb = new StringBuilder("");

	 public static void main(String[] args)  {

		Scanner s  = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n=s.nextLong(); S="";

		S1=Long.toString(n);

		while(n>9) {
			k=n%10;

			if(k>=5) {

				S=Long.toString(9-k)+S;
			}
			else {
				S=Long.toString(k)+S;
			}
			n=n/10;
		}

		if(S1.charAt(0)!='9') {
			int i = Character.getNumericValue(S1.charAt(0));
			if(i>=5) {

			System.out.println(9-i+S);
			}
			else {
				System.out.println(i+S);
			}

		} else {
			System.out.println(S1.charAt(0)+S);
		}

	/*	String S = "Ninel";
		char [] ch  = S.toCharArray();

		for(int i=0;i<ch.length/2;i++) {
			char c = ch[i];
			ch[i]=ch[ch.length-i-1];
			ch[ch.length-1-i]=c;
		}
		System.out.println(Arrays.toString(ch));*/

/*		S=s.nextLine();

		Pattern p = Pattern.compile("^[A-Z][a-z]+\\s[A-Z][a-z]+\\s([A-Z][a-z]+)$");
		Matcher m = p.matcher(S);
		boolean b = m.matches();

		System.out.println(b);*/
/*
		ArrayList<Integer> list = new ArrayList<Integer>();

		list.add(40);
		list.add(50);
		list.add(60);

		System.out.println(list);

		Iterator<Integer> it = list.iterator();
		it.next();
		it.remove();

		System.out.println(list);

		List<String> llist = new LinkedList<String>();

		llist.add("Sanan");
		llist.add("Seva");
		llist.add("Sadiq");

		System.out.println(llist);

		ListIterator<String> its = llist.listIterator();

		System.out.println(its.next());
		System.out.println(llist);*/

		/*try {
		 Pattern p = Pattern.compile("^[a-z]+");
		 Matcher m = p.matcher(S);
		 System.out.println(m.find());

		}catch (PatternSyntaxException e) {
			e.printStackTrace();
		}
*/

		/*BufferedReader reader = null;
		BufferedWriter writer = null;

		   try   {

			    reader = new BufferedReader(new FileReader("input.txt"));
			    writer = new BufferedWriter(new FileWriter("input.txt"));

		        String S = null;

		       while((S = reader.readLine()) != null) {

		       }
		        }

		      catch(IOException e) {
		    	e.printStackTrace();
		     }

		   finally {
			   try {
				   writer.close();
				   reader.close();
			   } catch (IOException e){
				   e.printStackTrace();
			   }
		   }
		   */

			out.flush();

	 }	public static boolean bobThere(String str) {
		  Pattern p = Pattern.compile("b[\\w]b");
		  Matcher m = p.matcher(str);
		  return m.matches();
		}

	 static void isSorted(int [] a) {
		 int k = 0;

		 for(int i=0;i<a.length-1;i++) {
			 if(a[i+1]-a[i]>=0) {
				 k++;
			 }
		 }
	 }

	 public static int fact12 (int n) {

		 return n==1 ? 1 : n*fact12(n-1);
	 }

	 public static boolean natural (int a,int b) {

		 String S = Integer.toString(b);

		 	for(int i=0;i<S.length();i++) {
		 		for(int j=i;j<S.length();j++) {
		 			String S1 = S.substring(i, j+1);
		 			if(Integer.parseInt(S1)==a) {
		 				return true;
		 			}

		 		}
		 	}

		 return false;
	 }

	 static String fromDecanyToAny (int n ,int k) {

		 String [] SS = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v",
					"w","x","y","z"};

		 StringBuilder Sb = new StringBuilder("");

		 int o ;

		 while(n>0) {
			 o=n%k;

			 n=n/k;
			 if(o>9) {
				 Sb=Sb.append(SS[o-10]);
			 }
			 else {
			 Sb=Sb.append(o);
			 }
		 }

		 return Sb.reverse().toString();

	 }

   static int sqrt (int a) {
	   int c = 0;
	   for(int i=1;i<=a/2;i++) {
		   if(i*i>a) return i-1;
		   else if(i*i==a) return i;
		//   else return -1;
		   c=i;
	   }
	   return c;
   }

   	static long skobki (int n) {

   		long [] C = new long [n+1];

   			C[0]=1;
   			  for (int i=1; i<=n; i++)
   			  {
   			    C[i]=0;
   			    for (int j=0; j<i; j++)
   			      C[i]+=C[j]*C[i-1-j];
   			  }

   				return C[n];
   			}

	   		static int solve(int n ) {
	   			int num = 0;
	   			while(n/5>0) {
	   				num+=n/5;
	   				n=n/5;
	   			}
	   			return num;
	   		}

       public static void bubbleSort (int [] a) {
           for(int i=0;i<a.length;i++) {
               for(int j=i+1;j<a.length;j++) {
                   if(a[i]>a[j]) {
                       int temp = a[i];
                       a[i]=a[j];
                       a[j]=temp;
                   }
               }
           }
       }

   public static void swap (int [] a,int start,int end) {

       int temp = a[start];
       a[start]=a[end];
       a[end]=temp;

       }

  static  void quicksort(int [] mas, int first, int last)   {

      int mid;
      int f=first, l=last;
      mid=mas[(f+l) / 2];
              do    {
                      while (mas[f]>mid) f++;
                      while (mas[l]<mid) l--;
                          if (f<=l)    {
                                  swap(mas,f,l);
                                  f++;
                                  l--;
                          }
              }
              while (f<l);
              if (first<l) quicksort(mas, first, l);
              if (f<last) quicksort(mas, f, last);
       }

      static String toBinary (BigInteger big) {
          String S = ""; BigInteger two = new BigInteger("2");
          while(big.compareTo(BigInteger.ZERO)==1) {
              S=big.mod(two)+S;
              big=big.divide(two);
          }
          return S;
      }

       static int [] shuffle (int [] a) {

          for(int i=0;i<a.length;i++) {
              int rand = (int)(Math.random()*a.length);

              for(int j=0;j<a.length;j++) {
                  int temp = a[j];
                  a[j]=a[rand];
                  a[rand]=temp;
              }

          }
              return a;
          }

      static int gcd (int a, int b) {
          return (b==0) ? a : gcd(b,a%b);
      }

      static int nok (int a ,int b) {
    	  int p =a*b;
          return p/gcd(a,b);
      }

      static BigInteger toDecany (String S) {

             BigInteger b = new BigInteger(S);

             BigInteger  k ,two = new BigInteger("2");

             BigInteger sum = BigInteger.ZERO;
             int i = 0;
             while(b.compareTo(BigInteger.ZERO)==1) {
                 k=b.mod(BigInteger.TEN);
                 sum=sum.add((k.multiply(two.pow(i))));
                 i++;
                 b=b.divide(BigInteger.TEN);
             }

             return sum;
          }

    static boolean prime(int n) {
    	if(n<2) return false;
          for(int i=2;i*i<=n;i++)
              if(n%i==0) return false;
          	return true;
      }

	static boolean palindrom (String S) {

    int num = 0;
    for(int i=0;i<S.length()/2;i++) {
        if(S.charAt(i)==S.charAt(S.length()-i-1)) num++;
    }
    return num==S.length()/2;

}

      static int binary (int key ,int [] a) {
             int lo = 0;
             int hi = a.length-1;

             while(lo<=hi) {

                 int med = (hi+lo)/2;

                 if(key<a[med]) hi=med-1;
                 else if (key>a[med]) lo=med+1;
                 else return med;

             }

            return -1;
         }

 static BigInteger fibonacci (long n) {

	  if(n<=1) return BigInteger.ONE;

		 ArrayList<BigInteger> list = new ArrayList<BigInteger>();
		 list.add(BigInteger.ONE); list.add(BigInteger.ONE);
		 for(int i=2;i<=n;i++) {
			 list.add(list.get(i-1).add(list.get(i-2)));
		 }

	 return list.get(list.size()-1);
			 }

 static int fact (int n) {
	 if(n==1) return 1;
	 else if(n==2) return 2;
	 else return fact(n-1)*n;
 }

}

import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Walker
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long n = in.nextLong();
        long ans = 0;
        long t = 1;
        while(n / 10 > 0){
            long a = n % 10;
            long b = 9 - (n % 10);
            ans += Math.min(a, b) * t;
            t *= 10;
            n /= 10;
        }
        long a = n % 10;
        long b = 9 - (n % 10);
        if(b != 0 && b < a){
            ans += t * b;
        }
        else{
            ans += t * a;
        }
        out.print(ans);
    }
}

//package com.company;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ChewbaccaAndNumbers {
    public static void main(String[] args) {
        Reader1 s1 = new Reader1();
        String[] numbers=s1.next().split("");
        for(int i=0;i<numbers.length;i++){
            if(i==0&&Integer.parseInt(numbers[i])==9){
                //this means ki shuru mei 9 hai and iska kuch nhi karna
            }
            else if(Integer.parseInt(numbers[i])>=5){
                numbers[i]=Integer.toString(9-Integer.parseInt(numbers[i]));
            }
        }for(String i:numbers) {
            System.out.print(i);
        }
    }
}
class Reader1 {
    BufferedReader br;
    StringTokenizer st;

    public Reader1() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

}

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        FastScanner scr = new FastScanner();
//        int t = scr.nextInt();
//        while (t-- > 0)
        solve(scr);
    }

    static void solve(FastScanner in) {

        String x = in.next();
        int k = 0;
        if (x.charAt(0) == '9')
            k++;
        for (int i = k; i < x.length(); i++) {
            if (x.charAt(i) - '0' > 9 - x.charAt(i) + '0') {
                x = x.substring(0, i) + (9 - (x.charAt(i) - '0')) + x.substring(i + 1);
            }
        }
        System.out.println(Long.parseLong(x));
    }

    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokinizer;

        public FastScanner() {
            initilize(System.in);
        }

        public FastScanner(String path) {
            try {
                initilize(new FileInputStream(new File(path)));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private void initilize(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        private String getToken() {
            while (tokinizer == null || !tokinizer.hasMoreTokens()) {
                try {
                    String str = reader.readLine();
                    if (str != null) tokinizer = new StringTokenizer(str);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokinizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(getToken());
        }

        public long nextLong() {
            return Long.parseLong(getToken());
        }

        public double nextDouble() {
            return Double.parseDouble(getToken());
        }

        public String next() {
            return getToken();
        }

        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.util.Scanner;
import java.util.Arrays;

public class program {

   public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
      String str=input.next();
      String str1="";
      char a;
      int count=0;
      for(int i=0;i<str.length();i++)
      {
          a=str.charAt(i);
         if(a>='5'){
              if(i==0&&a=='9')
              str1+=a;
              else
                  str1+=('9'-a);
          }
          else
              str1+=a;
       //   System.out.println(a);
      }
           System.out.println(str1);
 }
     }

import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

public class btp {

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char[] c=s.toCharArray();

		for(int i=0;i<c.length;i++){
			int n=c[i]-'0';
			if(9-n<n){
				n=9-n;
				char cc=(char) (n+'0');
				c[i]=cc;
				if(i==0&&c[i]=='0'){
					c[i]=s.charAt(0);
				}
			}
			//System.out.println(n);
		}
		System.out.println(new String(c));
		sc.close();
	}

}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        long n = input.nextLong();

        String s = "";

        s+=n;

        String s1 = "";

        if(s.charAt(0) >= '5' && s.charAt(0) < '9') {
            s1+= (57 - s.charAt(0));
        }
        else {
            s1+= s.charAt(0);
        }

        for(int i=1; i<s.length(); i++) {

            if(s.charAt(i) >= '5') {
                s1+= (57 - s.charAt(i));

            }
            else {
                s1+= s.charAt(i);
            }
        }

        System.out.println(s1);
    }

}

import java.util.*;

import java.util.Arrays;

public class FirstCode
{

     public static void main(String [] args) {
    	Scanner sc=new Scanner(System.in);
    	String k="";
    	int i;
           String s=sc.nextLine();

           for(i=0;i<s.length();i++)
           {
        	   if(i==0)
        	   {
        		   if(s.charAt(i)=='9')
        		   System.out.print('9');
        		   else
        		   {
        			   if(('9'-s.charAt(i))>s.charAt(i)-'0')
        				  k=k+s.charAt(i);
        			   else
        			   {
        				   k=k+('9'-s.charAt(i));
        			   }
        		   }

        	   }
        	   else {

    			   if(('9'-s.charAt(i))>s.charAt(i)-'0')
    				  k=k+s.charAt(i);
    			   else
    			   {
    				   k=k+('9'-s.charAt(i));
    			   }
        	   }
           }
           System.out.println(k);
     }
}

 import static java.lang.System.exit;
    import java.util.ArrayList;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Scanner;
    import java.util.*;
    /**
     *
     * @author abdelmagied
     */
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.HashMap;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import java.util.Scanner;

public class JavaApplication1 {

      public static void main(String[] arg){
          Scanner sc = new Scanner(System.in);

          String nextVal = sc.next();

          StringBuilder str = new StringBuilder(nextVal);

          for(int i = 0 ; i < str.length() ; i++){
              int v = Character.getNumericValue(str.charAt(i));
              int vv =  Integer.min(v , 9-v);
              if((vv == 0 && i != 0) || ( vv != 0 ))
              str.setCharAt(i, (char)(vv+48));
          }
          System.out.println(str.toString());
      }
}

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       String s=sc.next(),S="";

       for(int t=0;t<s.length();t++){
           char c=s.charAt(t);
            if(t==0&&('9'-c)==0) S+=c;
           else if(('9'-c)<(c-'0')){S+='9'-c;
           }else S+=c;
       }
       System.out.print(S);

    }
}

import java.util.Scanner;
public class acm {
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);

String x=in.next();
char arr[]=new char[x.length()];
arr=x.toCharArray();
for(int i=0;i<x.length();i++)
{

if(i==0&&arr[0]=='9')
	continue;
else if(arr[i]>='5')
	arr[i]=(char)(('9'-arr[i])+'0');

}

System.out.println(arr);

}
}

import java.util.*;
public class first
{

	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		String s = new String(input.next());
		StringBuilder changed = new StringBuilder(s);
		boolean b = true;
		for(int i =1; i < s.length(); i++)
			if(s.charAt(i) != '0')
				b = false;

//		if(!(b && s.charAt(0) == '9')){

		for(int i =0; i < s.length(); i++)
		{
			if(( '9'- changed.charAt(i) +'0') < changed.charAt(i) && !(i == 0 && changed.charAt(i) == '9'))
			{
				//String temp = changed.substring(0, i) + (char) ( '9'- s.charAt(i)+'0') + changed.substring(i+1, s.length());
				//if(Long.parseLong(temp) != 0)
					changed.setCharAt(i, (char) ( '9'- s.charAt(i)+'0'));
			}
		}

		System.out.println(Long.parseLong(changed.toString()));
	//}
		//else
		//{
			//System.out.println();
			//for(int i =0; i <s.length() -1; i++)
				//System.out.print(9);
		//}
		}

}

import java.util.Scanner;

/**
 ** Created by Alik on 11/8/2015.
 */
public class Problem_514A {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String number = in.nextLine();
        long result = 0;

        int temp;
        for (int i = 0; i < number.length(); i++){
            temp = number.charAt(i)-48;
            if ( !(i == 0 && temp == 9) && temp > 4)
                temp = 9-temp;
            result = result*10 + temp;
        }
        System.out.print(result);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String string = scanner.next();
        char[] chars = string.toCharArray();
        for (int i = 0; i < string.length(); i++) {
            int x = chars[i];
            if(x > 52 && (chars[i] != '9' || i != 0)){
                chars[i] = (char) (57-x+48);
            }
        }
        String ans = "";
        for (char value : chars) {
            ans += value;
        }
        long op = Long.parseLong(ans);
        System.out.println(op);
    }
}

 import java.util.*;
public class NewClass1 {

    public static void main(String [] args)
    {

        Scanner in=new Scanner(System.in);
       String s=in.next();

       for(int i=0;i<s.length();i++)
         {

              String d=""+s.charAt(i);
             int y=Integer.parseInt(d);
                 if(i==0&& y==9)
                     System.out.print("9");
                 else if(y<5)
       System.out.print(y);
                 else
                     System.out.print(9-y);

       }

         }
         }

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        String s=in.next();
        String o = new String();
        int xx=Character.getNumericValue(s.charAt(0));
        if (xx==9)o+=9;
       else if (xx>4){o+=(9-xx);}
        else o+=xx;
        for (int i=1;i<s.length();i++){
            int x=Character.getNumericValue(s.charAt(i));
            if (x>4 ){
                x=9-x;
                o+=String.valueOf(x);
            }
            else o+=(String.valueOf(x));

        }

        System.out.println(o);

    }
}

import java.util.Scanner;

public class Question514A {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		String ans="";
		if(s.charAt(0)=='9')
			ans=ans+s.charAt(0);
		else
		{
			if((s.charAt(0)-'0') >=5)
			{
				ans=ans+('9'-s.charAt(0));
			}
			else
				ans=ans+s.charAt(0);
		}
		for(int i=1;i<s.length();i++)
		{
			if((s.charAt(i)-'0') >=5)
			{
				ans=ans+('9'-s.charAt(i));
			}
			else
				ans=ans+s.charAt(i);
		}
		System.out.println(ans);
		}
	}

import java.util.*;
import java.io.*;
public class Main {
	static StreamTokenizer s = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    public static void main(String[] args) throws IOException {
		var out = new PrintWriter(System.out);
		var sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = 0;
		long m = 1;
		while (n > 0) {
			long d = n%10;
			n/=10;
			if (d == 9 && n == 0) a += d*m;
			else {
				d = Math.min(d, 9-d);
				a += d*m;
			}
			m*=10;
		}
		out.println(a);
		out.flush();
	}
	static int nextInt() throws IOException {
		s.nextToken();
		return (int)s.nval;
	}
}

import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    String a = scan.next();
    if (a.equals("9")) {
      System.out.println(a);
    } else {
    String build = "";
    for (int i =0; i < a.length(); i++) {
      char curChar = a.charAt(i);
      if (curChar > '4' && (curChar != '9' || i!=0)) {
        build = build + (char)(('9'-curChar)+48);
      } else {
        build = build + curChar;
      }
    }
    System.out.println(Long.valueOf(build));
    }
  }
}

import java.util.*;
import java.io.*;

//514A

public class Code270A{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long n = sc.nextLong();
        System.out.println(fancyFence(n));
    }

    public static long fancyFence(long n){
        ArrayList<Long> al = new ArrayList<>();
        long last = 0;
        long d = 0;
        while(n > 0){
            d = n%10l;
            last = d;
            if(d > 4){
                d = 9-d;
            }
            al.add(d);
            n = n/10;
        }
        if(d == 0)
            d = last;
        n = d;
        for (int i = al.size()-2 ; i >= 0; i--){
            n = n*10 + al.get(i);
        }
        return n;
    }

    public static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
       //ArrayList<Integer>rx=new ArrayList<>();
//HashSet<Integer> h=new HashSet<>();
int c=0;
String num=in.next();
        int xx=Character.getNumericValue(num.charAt(0));
        if (xx==9||xx<5){
            System.out.print(xx);
        }else System.out.print(9-xx);
for (int i=1;i<num.length();i++){
    int x=Character.getNumericValue(num.charAt(i));
    if (x>4){
        System.out.print(9-x);
    }else System.out.print(x);
}

    }
}

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();

        char[] array = s.toCharArray();

        int x = 0;
        int count = 0;

        for(int i=0;i<array.length;i++)
        {
            x = array[i] - '0';

            if(9-x<=x && count == 0 && 9-x>0)
            System.out.print(9-x);
            else if(9-x<=x && count == 0 && 9-x==0)
            System.out.print(x);
            else if(9-x<=x)
            System.out.print(9-x);
            else
            System.out.print(x);

            count = 1;
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Invert {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner scan = new FastScanner(System.in);
		String num = scan.next() ;
		StringBuilder sb = new StringBuilder("") ;
		for (int i = 0; i < num.length(); i++) {
			int t1 = num.charAt(i)-48 ;
			int t2 = 9 - (Integer.valueOf(num.charAt(i))-48) ;
			if (t1==9 &&num.length()>=1 && i==0) {
				sb.append(t1) ;
			}
			else if (t1>t2 && t2>=0) {
				sb.append(t2);
			}
			else {
				sb.append(t1);
			}

		}
		System.out.println(sb.toString());
	}

}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    FastScanner(InputStream stream) {
        try {
            br = new BufferedReader(new InputStreamReader(stream));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}

import java.util.*;
public class p104 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String x = in.next();
		char[] c = x.toCharArray();
		String ans=""; int a[] = new int [x.length()] ;
		for (int i = 0; i < c.length; i++) {
			if ((int)c[i]-48>=5) {
				if((int)c[i]-48==9&&i==0) {
					a[i]=(int)c[i]-48;
				}else {
					a[i] = 9-((int)c[i]-48);
				}
			}else {
				a[i]=(int)c[i]-48;
			}
			ans+=String.valueOf(a[i]);

		}
		System.out.println(ans);
	}

}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Main {

     // method to print the divisors
    static long printDivisors(long n)
    {

        long num = (long )Math.sqrt(n) , count = 0 ;
        // Note that this loop runs till square root
        for (int i=1; i<=num; i++)
        {
            if (n%i==0)
            {
                // If divisors are equal, print only one
                if (n/i == i) ++count ;
                  //  System.out.printf("%d ", i);

                else // Otherwise print both
                    count = count + 2;
                    //System.out.printf("%d %d ", i, n/i);
            }
        }
       return count;

    }

    // Driver method
    public static void main(String args[])
    {
           Scanner in = new Scanner(System.in);

           StringBuilder a = new StringBuilder(in.next());

           int A  = 0  , B = 0 ;

        for (int i = 1; i < a.length(); i++)
        {

             A = 9-(a.charAt(i)-'0' );
             B = a.charAt(i)-'0';

             a = (A < B)?a.replace(i, i+1, A+"") : a ;

        }

         A = 9-(a.charAt(0)-'0' );
          B = a.charAt(0)-'0';

          System.out.println( a = (A != 0 && A < B)?a.replace(0, 0+1, A+"") : a);

    }

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class TA {
	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		char[] a=in.nextToken().toCharArray();
		int i,b,n=a.length;
		long ans=0;
		for(i=0;i<n;i++){
			b=a[i]-'0';
			if(i==0&&(9-b)>0&&(9-b)<=4){
				ans=ans*10+(9-b);
			}else if(i>0&&(9-b)<=4){
				ans=ans*10+(9-b);
			}else{
				ans=ans*10+b;
			}
		}
		System.out.println(ans);
	}
	static class FastScanner{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}
		String nextToken(){
			while(st==null||!st.hasMoreElements())
				try{st=new StringTokenizer(br.readLine());}catch(Exception e){}
			return st.nextToken();
		}
		int nextInt(){return Integer.parseInt(nextToken());}
		long nextLong(){return Long.parseLong(nextToken());}
		double nextDouble(){return Double.parseDouble(nextToken());}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {

		InputReader in = new InputReader(System.in);
		long n = in.nextLong();
		long answer = n;
		long pos=1;

		for(long i=0;i<Math.ceil(Math.log10(answer));i++) {
			if(n!=9) {
				if((9-(n%10))<(n%10)) {
					long x = (2*(n%10)-9)*pos;
					answer 	-= x;
				}
			}
			n/=10;
			pos*=10;

		}

		System.out.println(answer);

	}
	 static class InputReader {
	        public BufferedReader reader;
	        public StringTokenizer tokenizer;

	        public InputReader(InputStream stream) {
	            reader = new BufferedReader(new InputStreamReader(stream), 32768);
	            tokenizer = null;
	        }

	        public String next() {
	            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	                try {
	                    tokenizer = new StringTokenizer(reader.readLine());
	                } catch (IOException e) {
	                    throw new RuntimeException(e);
	                }
	            }
	            return tokenizer.nextToken();
	        }

	        public int nextInt() {
	            return Integer.parseInt(next());
	        }

	        public long nextLong() {
	            return Long.parseLong(next());
	        }

	    }
}

import java.util.Scanner;

public class CodeforcesProblems {

	public static void main(String[] arg){

		Scanner sIn = new Scanner(System.in);
		String numStr = sIn.next();
		char[] tmpChars = numStr.toCharArray();
		int index = 0;

		// deal with result which is starting with '0' after inverting.
		if (tmpChars[0] == '9') {
			System.out.print(9);
			index = 1;
		}

		for (; index < tmpChars.length; index++){
			int tmpInt = tmpChars[index] - '0';
			if (tmpInt > 4)
				tmpInt = 9 - tmpInt;
			System.out.print(tmpInt);
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;

		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

}

class TaskD {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
	}

}

class TaskA {

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		String number = in.next();
		StringBuffer result = new StringBuffer();
		for(int i=0;i<number.length();++i){
			char ch = number.charAt(i);
			if(i==0&&ch=='9'){
				result.append(ch);
				continue;
			}
			result.append(invert(ch));
		}
		out.println(result.toString());
	}

	private char invert(char ch) {
		if(ch>'4'){
			ch -='0';
			int r = 9-(int)ch;
			return (char)('0'+r);
		}
		return ch;
	}

}

class Point implements Comparable<Point>{

	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
	int x;
	int y;
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Point other = (Point) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

	@Override
	public int compareTo(Point p2) {
		return x*x + y*y - p2.x*p2.x - p2.y * p2.y;
	}

}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter out)
			throws IOException {

		int n = in.nextInt();
		int x0 = in.nextInt();
		int y0 = in.nextInt();
		PriorityQueue<Point> points = new PriorityQueue<Point>();

		for(int i=0;i<n;++i){
			points.add(new Point(in.nextInt()-x0,in.nextInt()-y0));
		}
		int shots = 0;
		while(!points.isEmpty()){

			Point p = points.poll();
			int ddx = p.x;
			int ddy = p.y;
			if(ddx==0&ddy==0){
				continue;
			}
			shots++;

			for(int f=2;f<=Math.min(ddx, ddy);++f){
				while(ddx%f==0&&ddy%f==0){
					ddx/=f;
					ddy/=f;
				}
			}

			int i=1;
			int dx = ddx;
			int dy = ddy;
			while(Math.abs(dx)<=10000&&Math.abs(dy)<=10000){
				dx = ddx*i;
				dy = ddy*i;
				Point np = new Point(dx,dy);
				points.remove(np);
				i++;
			}

			i=-1;
			dx = -ddx;
			dy = -ddy;
			while(Math.abs(dx)<=10000&&Math.abs(dy)<=10000){
				dx = ddx*i;
				dy = ddy*i;
				Point np = new Point(dx,dy);
				points.remove(np);
				i--;
			}
		}
		if(shots==0){
			shots++;
		}
		out.println(shots);
	}

}

class TaskC {

	class Pair{

		int p1;
		int p2;

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + p1;
			result = prime * result + p2;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (p1 != other.p1)
				return false;
			if (p2 != other.p2)
				return false;
			return true;
		}
		private TaskC getOuterType() {
			return TaskC.this;
		}

	}

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		int n = in.nextInt();
		int m = in.nextInt();

		Map<Pair, List<String>> map = new HashMap<Pair,List<String>>();

		for(int i=0;i<n;++i){
			String s = in.next();
			int hash = hash(s);
			Pair p = new Pair();
			p.p1 = s.length();
			p.p2 = hash;

			if(map.containsKey(p)){
				map.get(p).add(s);
			}else{
				map.put(p, new ArrayList<String>());
				map.get(p).add(s);
			}
		}

		int[] d = new int[]{-1,-2,1,2};
		for(int i=0;i<m;++i){
			String s = in.next();
			int hash = hash(s);
			boolean found = false;
			for(int dd:d){
				Pair p = new Pair();
				p.p1 = s.length();
				p.p2 = hash+dd;
				if(map.containsKey(p)&&onePosition(map.get(p),s)){
					out.println("YES");
					found = true;
					break;
				}
			}
			if(!found){
				out.println("NO");
			}
		}

	}

	private boolean onePosition(List<String> list, String s) {
		for(String str:list){
			int diff = 0;
			for(int i=0;i<str.length();++i){
				if(str.charAt(i)!=s.charAt(i)){
					diff++;
					if(diff>1){
						break;
					}
				}
			}
			if(diff==1){
				return true;
			}
		}
		return false;
	}

	private int hash(String s) {
		int r=0;
		for(int i=0;i<s.length();++i){
			r+=(s.charAt(i)-'a');
		}
		return r;
	}

}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

}

//package codeforcesround.2015.round291;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class ChewbaccaAndNumber {
        BufferedReader br; PrintWriter out; StringTokenizer tk; boolean eof, submit;
        public static void main(String args[]) throws IOException { new ChewbaccaAndNumber(); }

        String ntk() { while (tk == null || !tk.hasMoreTokens()) { try { tk = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return null; } } return tk.nextToken(); }
        String nln() { try { return br.readLine(); } catch (IOException e) { eof = true; return null; } }
        String ns() { return ntk(); }
        int ni() throws IOException { return Integer.parseInt(ntk()); }
        long nl() throws IOException { return Long.parseLong(ntk()); }
        float nf() throws IOException { return Float.parseFloat(ntk()); }
        double nd() throws IOException { return Double.parseDouble(ntk()); }
        void debug(Object... o) { if(!submit) { System.out.println(Arrays.deepToString(o)); } }

        public ChewbaccaAndNumber() throws IOException {
                long start = System.currentTimeMillis();
                submit = !false;
                if(submit == false) br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\input.txt")));
                else br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);

                int T = 1; while(T-- > 0) solve();

                long end = System.currentTimeMillis();
                debug(end - start, " ms");
                out.close();
        }

        String X;
        void solve() throws IOException {
                X = nln();
                StringBuilder sb = new StringBuilder();

                int idx = 0;
                if(X.charAt(idx) == '9'){
                        sb.append("9");
                        idx++;
                }

                for(int i=idx; i<X.length(); i++) {
                        int value = Integer.parseInt(X.charAt(i)+"");
                        if(value >= 5) {
                                value = 9 - value;
                        }
                        sb.append(value);
                }
                while(sb.charAt(0) == '0') {
                        sb.deleteCharAt(0);
                        if(sb.length() == 0)
                                break;
                }
                if(sb.length() > 0)
                        out.println(sb.toString());
                else {
                        if(X.charAt(X.length()-1) != '9') {
                                int value = X.charAt(X.length()-1);
                                if(value >= 5)
                                        value = 9 - value;
                                out.println(value);
                        } else {
                                out.println("9");
                        }
                }
        }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map.Entry;

public class Main {
	static InputStream is;

	public static void main(String[] args) {
		is = System.in;
		solve();
	}

	static void solve() {
		String s = ns();
		boolean trueOrFalse = false;
		for (int i = 0; i < s.length(); i++) {
			if (Character.getNumericValue(s.charAt(i)) != 9) {
				trueOrFalse = true;
			}
			if (trueOrFalse == true) {
				if (Character.getNumericValue(s.charAt(i)) > 4) {
					System.out.print(Integer.toString((9 - Character.getNumericValue(s.charAt(i)))));
				} else {
					System.out.print(s.charAt(i));
				}
			}
			if (trueOrFalse == false) {
				System.out.print(s.charAt(i));
				trueOrFalse = true;
			}
		}
	}

	static byte[] inbuf = new byte[4096];
	static int lenbuf = 0, ptrbuf = 0;

	static int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	static boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	static int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	static double nd() {
		return Double.parseDouble(ns());
	}

	static char nc() {
		return (char) skip();
	}

	static String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	static char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	static int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	static long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
}

import java.math.BigInteger;
import java.util.*;
public class xyz {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	BigInteger x=sc.nextBigInteger();

	String y=x.toString();
	int  arr[]=new int [y.length()];
	BigInteger t=new BigInteger("0");
	BigInteger j=new BigInteger("0");

	BigInteger bi = BigInteger.valueOf(y.length());
	for(int i =0;i<y.length();i++){
		arr[ i]=y.charAt( i)-'0';
		String s=(y.substring((int)i,(int)i+1));
		int a=Integer.parseInt(s);
		if(i==0&&a!=9&&a>=5){
			a=9-a;

		}
		if(i==0&&a==9)
		{}
		if(i>0&&a>=5){
			a=9-a;
		}

		 System.out.print(a);
	}

	}

}

import java.util.Scanner;

public class MainTest{

	///////////////////////////////////////////////////////////////////////////////////
	public static void main(String q[]) {
		Scanner scan=new Scanner(System.in);

		long x;
		x=scan.nextLong();       // input x

		StringBuffer str=new StringBuffer(x+"");       //convert x to String

		for(int i=0;i<str.length();i++) {             //inverting the numbers

			char ch=str.charAt(i);
			int y=Character.getNumericValue(ch);

			if(y>4) {
				y=9-y;
				String n=""+y;
			str.replace(i,i+1,n);
			}
		}

		while(str.charAt(0)=='0'){
			if(str.length()==1)break;
			str.replace(0,1,"9");
		}

		if(str.charAt(0)=='0')
		System.out.print(9);
		else
			System.out.print(str);

	}
	///////////////////////////////////////////////////////////////////////////////////

}

import java.util.Scanner;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        String s = scanner.next();
        char[] c = new char[s.length()];
        int cc = 0;
        for (int i = 0; i < s.length(); i++) {
            if (i != 0 || s.charAt(i) != '9') {
                int a = Integer.parseInt(String.valueOf(s.charAt(i)));
                if ((9 - a) >= 0 && (9 - a) <= a) {
                    int t = 9 - a;
                    String tt = String.valueOf(t);
                    c[cc] = tt.charAt(0);
                    cc += 1;
                } else {
                    c[cc] = s.charAt(i);
                    cc += 1;
                }
            } else {
                c[cc] = s.charAt(i);
                cc += 1;
            }
        }
        for (char v : c) {
            System.out.print(v);
        }
    }
}

import java.math.BigInteger;
import java.util.Scanner;

/**
 * Created by karawat on 6/2/16.
 */
public class InvertingNumber {

    static byte[] nine = {9};
    public static final BigInteger NINE = new BigInteger(nine);

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        BigInteger t=s.nextBigInteger();
        BigInteger u = BigInteger.ZERO;
        BigInteger multiplier = BigInteger.ONE;
        int numberOfDigitsT = 0;
        while(!t.equals(BigInteger.ZERO)){
            BigInteger[] QandR = t.divideAndRemainder(BigInteger.TEN);
            u = u.add(multiplier.multiply(InversionMethod(QandR[1])));
            t=QandR[0];
            multiplier = multiplier.multiply(BigInteger.TEN);
            numberOfDigitsT ++;
        }
        int numOfDigitsU = 0;
        BigInteger copyU = u;
        while(!u.equals(BigInteger.ZERO)){
            u = u.divide(BigInteger.TEN);
            numOfDigitsU ++;
        }

        if (numOfDigitsU < numberOfDigitsT){
            BigInteger Nine10 = NINE.multiply(multiplier.divide(BigInteger.TEN));
            copyU = copyU.add(Nine10);
        }

        System.out.println(copyU);

    }

    public static BigInteger InversionMethod(BigInteger digit){
        byte[] nine = {9};
        byte[] five = {5};
        BigInteger NINE = new BigInteger(nine);

        //System.out.println(NINE.subtract(digit));

        BigInteger FIVE = new BigInteger(five);
        if (digit.compareTo(FIVE) <0)
            return digit;
        else
            return  NINE.subtract(digit);
    }

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package Codeforces;

/**
 *
 * @author Administrator
 */
import java.lang.StringBuffer;
import java.util.Scanner;

public class c524A {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s0 = in.next();
        StringBuffer s = new StringBuffer(s0);
        StringBuffer s2 = new StringBuffer();
        int i = 0, n = -1;
        if (s.charAt(0) == '9')
        {
            s2.insert(++n, '9');
            i++;
        }
        while (i < s.length()) {
            if (s.charAt(i) - '0' > ('9' - s.charAt(i))) {
                s2.insert(++n, '9' - s.charAt(i));
            } else s2.insert(++n, s.charAt(i));
            i++;
        }
        System.out.println(s2);
    }
}

// package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scan = new Scanner(System.in);

        String str = scan.nextLine();
        char [] s = new char[str.length()];
        for(int i = 0; i < str.length(); i++) {
            s[i] = str.charAt(i);
        }

        if(s[0] >= '5' && s[0] != '9') {
            s[0]  = (char)('9' - s[0]+ 48);
        }

        for(int i = 1; i < str.length(); i++) {
            if(s[i] >= '5') {
                s[i] = (char) ('9' -s[i] + 48);
            }
        }

        System.out.println(s);
    }
}

import java.util.Scanner;

public class hello82 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long n = input.nextLong();
//		long smallest = -1;
		long newlong=0;
		long number =1;
		while(n!=0){
			long temp = n %10;

//			System.out.prlongln(temp);
			if(temp >=5){
				if(n ==9){
					temp = 9;
				}
				else{
					temp = 9-temp;
				}

			}
			newlong = temp * number + newlong;
			number *=10;
			n/=10;
		}
			System.out.println(newlong);
	}
}

/*
ID: benkhad2
PROG : chewbacca
LANG: JAVA
TASK: Chewbacca And Numbers
*/
import java.io.*;
import java.util.Scanner;

public class chewbacca {
  public static void main (String [] args) throws IOException {
   /* // Use BufferedReader rather than RandomAccessFile; it's much faster
    BufferedReader f = new BufferedReader(new FileReader("chewbacca.in"));
                                                  // input file name goes above
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("chewbacca.out")));
    // Use StringTokenizer vs. readLine/split -- lots faster*/

	Scanner read = new Scanner(System.in);
    String ch = read.next();
    String ch1="";

    for(int i=0;i<ch.length();i++){
    	if(Character.getNumericValue(ch.charAt(i))>4){
    		if(i==0 && ch.charAt(i)=='9'){
    			ch1+="9";
    		}else{
    			ch1+=Integer.toString((9-Character.getNumericValue(ch.charAt(i))));
    		}
    	}else{
    		ch1+=ch.charAt(i);
    	}
    }

   System.out.println(ch1);

   // out.close();
    System.exit(0);

  }

}

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        String x = in.next();
        String g = "";
        int min = 9;
        for (int i = 0; i < x.length(); i++) {
            int l = x.codePointAt(i) - 48;
            int l1 = x.codePointAt(i) - 48;
            min = Math.min(min,x.codePointAt(i) - 48);
            l1 = 9 - l1;
            l = Math.min(l1,l);
            if (l == 0){
                if (g.length() == 0){
                    g += x.charAt(i);
                }
                else g += 0;
            }
            else g += l;
        }

        out.print(g);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

}

import java.util.*;
import java.io.*;
public class house
{
	public static void main(String args[]) throws IOException
	{
		try{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		char arr[]=br.readLine().toCharArray();
		int ans[]=new int[arr.length];
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]>='5')
			{
				ans[i]=9-Integer.parseInt(""+arr[i]);
			}
			else
			{
				ans[i]=Integer.parseInt(""+arr[i]);
			}
		}
		if(ans[0]==0)
		{
			ans[0]+=9;
		}
		String aw="";
		aw=Arrays.toString(ans).replaceAll(",","").replaceAll(" ","");
		aw=aw.substring(1,aw.length()-1);
		System.out.println(aw);
	}
	catch(Exception e){}
}}

import java.util.Scanner;

public class Main{
    private static String InvertDigitAt(int dig_index, String number){
        String invert_number = "", digit;
        for(int index = 0; index < number.length(); index++){
            digit = "" + number.charAt(index);
            if(index == dig_index && 9 - Integer.parseInt(digit) < Integer.parseInt(digit))
                invert_number += 9 - Integer.parseInt(digit);
            else invert_number += digit;
        }
        return invert_number;
    }

    private static String MinInvertNumber(String number){
        for(int index = number.length() - 1; index >= 0; index--)
            if(index == 0 && InvertDigitAt(index, number).charAt(index) != '0' || index != 0)
                number = InvertDigitAt(index, number);
        return number;
    }

    public static void Solve() {
        Scanner scanner = new Scanner(System.in);
        System.out.println(MinInvertNumber(scanner.nextLine()));
    }

    public static void main(String[] args){
        Solve();
    }
}

import java.util.Scanner;
import java.lang.Math;

public class Main{
    public static void main(String[] args){
        String str = new Scanner(System.in).next();
        int len = str.length();String ret=(Math.min(Integer.parseInt(str.charAt(0)+""),9-Integer.parseInt(str.charAt(0)+"")))==0?"9":Math.min(Integer.parseInt(str.charAt(0)+""),9-Integer.parseInt(str.charAt(0)+""))+"";
        for(int i=1; i<len; i++)
            ret+=Math.min(Integer.parseInt(str.charAt(i)+""),9-Integer.parseInt(str.charAt(i)+""));
        System.out.println(ret);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Solution {
    public static void main (String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = in.next();
        String[] s2 = s.split("");
        StringBuilder sb = new StringBuilder();
        for (String c : s2) {
            int x = Integer.parseInt(c);
            if (x > 4) x = 9 - x;
            sb.append(x);
        }
        if (sb.charAt(0) == '0') sb.replace(0, 1, "9");
        System.out.println(sb.toString());
        in.close();
    }

}

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

/*
	  br = new BufferedReader(new FileReader("input.txt"));
	  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	  br = new BufferedReader(new InputStreamReader(System.in));
	  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			String s = nextToken();
			if(s.charAt(0) == '9')
				pw.print(s.charAt(0));
			else
				pw.print(Math.min(s.charAt(0)-'0', 9 - (s.charAt(0)-'0')));
			for(int i = 1; i < s.length(); i++) {
				int curr = s.charAt(i) - '0';
				pw.print(Math.min(curr, 9 - curr));
			}
			pw.println();
		}
		exitImmediately();
	}

	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private static String nextLine() throws IOException  {
		if(!br.ready()) {
			exitImmediately();
		}
		st = null;
		return br.readLine();
	}

	private static String nextToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			if(!br.ready()) {
				exitImmediately();
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String num = in.nextLine();
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for(int i =0; i<num.length(); i++){
            int d = num.charAt(i)-'0';
            if(d>4){
                d=9-d;
            }

            if(first&&d==0){
                sb.append(9);
                first=false;
                continue;
            }
            sb.append(d);
            first=false;
        }
        System.out.println(sb);
    }
}

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char[] s = in.next().toCharArray();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.length; ++i){
            if (Character.getNumericValue(s[i])>4){
                int temp = 9-Character.getNumericValue(s[i]);
                if (i == 0 && temp == 0) ans.append(9);
                else ans.append(temp);
            } else {
                ans.append(s[i]);
            }
        }
        out.println(ans);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}

import java.util.Scanner;

public class A {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        char[] num = sc.next().toCharArray();
        StringBuilder sb = new StringBuilder();
        int cur;
        boolean first = true;
        for (int i = 0; i < num.length; i++) {
            cur = num[i]-48;
            cur = cur>4?9 - cur:cur;
            if (first) {
                if(cur<=0) {
                    cur = num[i]-48;
                }
                first = false;
            }
            sb.append(cur);
        }
        System.out.println(sb.toString());
    }
}

import java.util.Scanner;

public class _514A_ {
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	char[] s = in.next().toCharArray();
	for (int i = 0; i < s.length; i++)
	    if (s[i] > 0x34 && !(i == 0 && s[i] == '9'))
		s[i] = (char) (0x39 - s[i] + 0x30);
	System.out.println(new String(s));
    }

}

import java.util.Scanner;

public class DIV291A {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		 String s = sc.next();
		 String ss = "";
		 for(int i=0;i<s.length();i++){
			 Character ch = s.charAt(i);

			 if((i == 0 && (ch == '9' || ch=='0'))){
				 ss+=ch;
				 continue;
			}

			 if (Integer.parseInt(Character.toString(ch)) >= 5 ){
				 ss += Integer.toString(9 - Integer.parseInt(Character.toString(ch)));
			 }else{
				 ss+=ch;
			 }
		 }

		 System.out.println(ss);
	}

}

import java.util.Scanner;

public class problema {

	public static void main(String[] args) {
	Scanner myscanner=new Scanner(System.in);
	String x=myscanner.next();
      int[] result=new int[34];
      int count=0;
      if(x.charAt(0)=='9')
  		result[count++]=(x.charAt(0)-48);
      else if(x.charAt(0)>='5')
    	 result[count++]=9-(x.charAt(0)-48);
      else
  		result[count++]=(x.charAt(0)-48);

	for(int i=1;i<x.length();i++)
	{

		if(x.charAt(i)>='5')
		result[count++]=9-(x.charAt(i)-48);
		else
		result[count++]=(x.charAt(i)-48);

	}
	int i;
	for( i=0;i<count;i++){
		if(result[i]>0)
			break;
	}
	for(int j=i;j<count;j++)
		System.out.print(result[j]);
	System.out.println();

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CF291A {
	private FastScanner in;
	private PrintWriter out;

	public void solve() throws IOException {
		long a = in.nextLong();
		String n = a + "";
		char[] c = new char[n.length()];
		for (int i = 0; i < n.length(); i++){
			c[i] = n.charAt(i);
		}
		for (int i = 0; i < n.length(); i++){
			int nxt = n.charAt(i) - '0';
			if (i == 0 & (9 - nxt) == 0) continue;
			else if (9 - nxt >= nxt) continue;
			c[i] = (char) (9 - nxt + '0');
		}
		out.println(new String(c));
	}

	public static void main(String[] args) {
		new CF291A().run();
	}

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

import java.util.*;
import java.io.*;
import java.math.*;

public class test {

static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
	return Long.parseLong(next());
    }

}

 static class Task {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
  		while(testNumber-->0) {
			char[] n = in.next().toCharArray();
			int len = n.length;
			for(int i=0;i<len;++i) {
				int ch = n[i];
				int ch1 = ('9'-n[i])+48;
				//out.println(" ch = "+ch+" ch1 = "+ch1);
				if(i==0) {
					if(ch1!=48)
						n[i] = (char) Math.min(ch,ch1);
				}
				else
					n[i] = (char) Math.min(ch,ch1);

			}
			out.println(n);

    		}
	}

}

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int test  = 1;
        solver.solve(test, in, out);
        out.close();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ChewbacaAndNumbers {
	public static void main(String[] args)throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i <s.length(); i++) {
			if('9'-s.charAt(i) < s.charAt(i) - '0' )
				if(i==0 && s.charAt(i) == '9')
					sb.append('9');
				else
					sb.append('9'-s.charAt(i));
			else
				sb.append(s.charAt(i));
		}
		System.out.println(sb);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}
}

/*
Author - Prasenjeet Biswal
Date - 17/01/2016
*/

import java.util.*;
import java.lang.*;
import java.io.*;

 public class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner reader=new Scanner(System.in);
        String input=reader.nextLine();
        /*int start=0;
        for (char a:input.toCharArray())
        {
            if((a!='9' && start!=0)&&'9'-a+48<a)
                System.out.print((char)('9'-a+48));
            else
                System.out.print(a);

        }*/
        for(int i=0;i<input.length();i++)
        {
            if('9'-input.charAt(i)+48>input.charAt(i))
                System.out.print(input.charAt(i));
            else
            {
                if(i==0 && input.charAt(i)=='9')
                    System.out.print(input.charAt(i));
                else
                    System.out.print((char)('9'-input.charAt(i)+48));
            }
        }

    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       long n=sc.nextLong();
       if(n<10)
       System.out.print(n);
       else{
       String s=Long.toString(n);
       int[] a=new int[s.length()];
       for(int i=0;i<s.length();i++){
           a[i]=((int)s.charAt(i))-48;
           if(a[i]<5)
           System.out.print(a[i]);
           else{
               if(i==0 && a[i]==9)
               System.out.print(9);
               else
               System.out.print(9-a[i]);
           }
       }
       }
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);

        String str = in.nextLine();

        long num = Long.parseLong(str);

        String res="", temp="";
        char ch;

//      if( num == Math.pow(10, str.length()) - 1 ){
//          System.out.println("9");
//      }
//

        /*
        if( str.length() == 1 ){
            ch = str.charAt(0);

            if( ch == '9' )
                System.out.println( ch );
            else{
                if( ch >= '5'){
                    System.out.println( 9 - ch);
                }
                else{
                    System.out.println( ch );
                }
            }
        }
        */
        for(int i=0 ; i<str.length() ; i++){
            ch = str.charAt(i);

            if( i == 0 && ch == '9' ){
                temp += ch;
            }

            else if( ch >= '5' ){
                temp += ( 9 - (ch - '0' ) );
            }
            else{
                temp += ch;
            }
        }

        int flag = 0;

        for(int i=0; i<temp.length(); i++){
            if( flag == 0 && temp.charAt(i) == '0' ){
                continue;
            }
            else{
                res += temp.charAt(i);
                flag = 1;
            }
        }

        System.out.println(res);

//          if( res.length() != 0 ){
//              System.out.println(res);
//          }
//      }
//      else if( res.length() == 1 && res.charAt(0) == '0' ){
//          System.out.println("9");
//      }
    }

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class FirstTask {

    static int getMin(int firstNumber,int secondNumber)
    {
        if(firstNumber<=secondNumber)
            return firstNumber;

        return secondNumber;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String firstLine=br.readLine();
        int length=firstLine.length();
        if(firstLine.charAt(0)=='9')
            System.out.print('9');
        else
            System.out.print(getMin((int)firstLine.charAt(0)-'0',9-((int)firstLine.charAt(0)-'0')));
        for(int i=1;i<length;i++)
        {
            int currentDigit=(int)firstLine.charAt(i)-'0';
                System.out.print(getMin(currentDigit,9-currentDigit));
        }
    }

}

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.math.BigInteger;

public class CF514A {

	public static void main(String[] args)throws Exception  {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for(String ln;(ln=in.readLine())!=null;){
			StringBuilder sb = new StringBuilder();
			int indexZero = -1;
			for(int i=0;i<ln.length();++i){
				int num = ((int) Math.min(ln.charAt(i)-'0', 9-(ln.charAt(i)-'0') ));
				if(num==0 && i==0)
					sb.append(9 );
				else
					sb.append(num );
			}
			BigInteger b = new BigInteger(new String(sb));
			if(b.equals(BigInteger.ZERO))
				System.out.println(9);
			else
				System.out.println(b);
		}
	}

}

import java.util.Scanner;

public class PbTest {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		String Num = input.next();

		char[] sNum = Num.toCharArray();
		for (int i = 0; i < Num.length(); i++)
				if (Integer.valueOf(sNum[i]) >= '5')
					sNum[i] = (char) (9 - Character.getNumericValue(sNum[i]) + '0');
		if(sNum[0] == '0')
			sNum[0] = '9';
		Num = String.valueOf(sNum);
		System.out.println(Num);
	}
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] c1 = s.nextLine().toCharArray();
        char[][] r = {{'0', '1', '2', '3', '4', '4', '3', '2', '1', '9'},
                      {'0', '1', '2', '3', '4', '4', '3', '2', '1', '0'}};
        for(int i = 1; i < c1.length; i++) {
            c1[i] = r[1][c1[i]-'0'];
        }
        String str = ""+r[0][c1[0]-'0'];
        for(int i = 1; i < c1.length; i++) {
            str += c1[i];
        }
        System.out.print(Long.parseLong(str));
    }
}

import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

    public static void main(String[] args) throws IOException {
        Reader scn = new Reader();
        StringBuilder res = new StringBuilder();
        long x = scn.nextLong();
        long ans = 0;
        long place = 1;
        while (x > 0) {
            long rem = x % 10;
            if (x / 10 == 0) {
                if (rem >= 5 && rem != 9) {
                    rem = 9 - rem;
                }
            } else {
                if (rem >= 5) {
                    rem = 9 - rem;
                }
            }
            x /= 10;
            ans += place * rem;
            place *= 10;
        }
        res.append(ans);
        System.out.print(res);
    }
}

import java.util.Scanner;

public class Main {

    /**
     * @param args
     */

    int[][][][] asdf = new int[130][130][130][8];
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Main test1 = new Main();
        test1.read();
        test1.write();

    }

    private void write() {
        // TODO Auto-generated method stub

    }

    private void read() {
        // TODO Auto-generated method stub
        Scanner fi = new Scanner(System.in);

        String n = fi.next();
        String kq = "";
        while (n.length() != 0) {

            int temp = Integer.valueOf(n.charAt(n.length() - 1)) - 48;
            if ((n.length() == 1) && (n.charAt(0) == '9'))
                kq = '9' + kq;
            else {

                if ((9 - temp) < temp)
                    kq = String.valueOf(9 - temp) + kq;
                else
                    kq = String.valueOf(temp) + kq;
            }
            n = n.substring(0, n.length() - 1);
            // n /= 10;
        }
        while ((kq.length() >= 1) && (kq.charAt(0) == '0'))
            kq = kq.substring(1, kq.length());
        System.out.println(kq);
    }
}

import java.util.Scanner;

public class ChewNumber {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        long min = 0;
        long number = scanner.nextLong();

        long factor = 1;

        while (number > 0) {
            long digit = number % 10;
            if (number != 9) {
                min += Math.min(9 - digit, digit) * factor;
            } else {
                min += number * factor;
            }
            factor *= 10;
            number /= 10;
        }

        System.out.println(min);
    }
}

//package Code;

import java.util.*;
import java.math.*;
import java.lang.System;
import java.nio.CharBuffer;
import static java.lang.System.*;
import java.io.InputStream;
import java.sql.Time;

public class Main
{

    public static void main(String[] args)
    {
        Integer b;
        Integer c, d;
        Integer i;
        Integer j, k, t, n;
        Scanner in = new Scanner(System.in);
        String s = in .nextLine();
        StringBuffer ans = new StringBuffer(s);
        b = 0;

        for (i = 0; i < s.length(); i++)
        {
            b = (int) s.charAt(i);
            b = b % 48;
            if (b >= 5)
            {
                b = 9 - b;
                // Character ca=(char)(b+48);
                ans.setCharAt(i, (char)(b + 48));
            }
        }

        if (ans.charAt(0) == '0')
        {
            ans.setCharAt(0, '9');
        }

        System.out.println(ans);

    }

}

import java.io.*;
public class war{
    public static void main(String[] args) throws  IOException {
      InputStreamReader r=new InputStreamReader(System.in);
      BufferedReader br=new BufferedReader(r);

      String input=br.readLine();
      String ret="";
if(input.length()<=1){
      System.out.println(input);
}
      else{

      int i=0;
      if(input.charAt(i)=='9'){
            ret+="9";
            i++;
      }
      while(i<input.length()){

            int p=Integer.parseInt(String.valueOf(input.charAt(i)));

             if(9-p>=p){
ret+=String.valueOf(input.charAt(i));
            }
            else{
                  ret+=Integer.toString(9-p);
            }
            i++;
      }
      System.out.println(ret);

}
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//http://codeforces.com/problemset/problem/514/A
public class Chewbacca_And_Number {
	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String number = br.readLine();
		int x; String temp; char c;
		for(int i = 0; i<number.length(); i++){
			int n = Integer.parseInt(number.substring(i, i+1));
			if(9-n<n){
				x = 9-n;
				temp = "" + x;
				c = temp.charAt(0);
				number = number.replace(number.charAt(i), c);
			}else{

			}
		}
		if(number.charAt(0)=='0'){
			number = '9' + number.substring(1);
		}
		System.out.println(number);

	}

}

import java.util.Scanner;

/**
 * Created by zephyr on 2/14/15.
 */
public class Invert {

        //Scanner cin = new Scanner(System.in);
        //String input = cin.next();
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        StringBuilder sb = new StringBuilder();
        char[] inputArray = input.toCharArray();
        int start = -1;
        for (char digit : inputArray){
            if (digit >= '5'){
                if (start == - 1 && digit == '9') {sb.append('9'); start = 0;}
                else  sb.append('9' - digit);
            }else sb.append(digit);
            start = 0;
        }

        long num = (Long.parseLong(sb.toString()));
        if (num != 0){
            System.out.println(num);
        }else{
            System.out.println(9);
        }
    }

}

import java.io.*;
import java.util.StringTokenizer;

public class ProblemA {

    private static Scanner in;
    private static Output out;

    public static void solve() throws Exception {
        String line = in.nextLine().replaceAll(" ", "");
        int a[] = new int[line.length()];
        int i = 0;
        for (char c : line.toCharArray()) {
            int v = c - '0';
            if (v == 9 && i == 0) {
                a[i++] = v;
                continue;
            }
            if (v >= 5) {
                v = 9 - v;
            }
            a[i++] = v;
        }
        String res = "";
        for (i = 0; i < a.length; i++) {
            if (a[i] == 0) {
                continue;
            } else {
                break;
            }
        }
        if (i == a.length) {
            out.println(line);
            return;
        }
        for (; i < a.length; i++) {
            out.print(a[i]);
        }
        out.println();

    }

    public static void main(String[] args) throws Exception {
        initReaderWriter();
        solve();
        out.close();
    }

    private static void initReaderWriter() throws Exception {
        boolean isFile = false;
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

        public Scanner() {
            bf = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader291_A in = new InputReader291_A(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        String p = in.next();
        String s = "";
        for (int i = 0; i < p.length(); i++) {
            if (i == 0 && Integer.parseInt(p.charAt(i)+"") == 9) {
                s += p.charAt(i);
                continue;
            }
            if (Integer.parseInt(p.charAt(i) + "") >= 5) {
                s += (9-Integer.parseInt(p.charAt(i)+""));
            }
            else {
                s += p.charAt(i);
            }
        }
        out.print(s);
        out.flush();

    }
}
class InputReader291_A {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader291_A(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next(){
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong(){
        return Long.parseLong(next());
    }
    public double nextDouble(){
        return Double.parseDouble(next());
    }

}

import java.util.*;
import java.io.*;

public class ChewbaccaNum {
   public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String x = input.next();

        for (int i = 0; i < x.length(); i++) {
            if(i== 0 && x.charAt(i) == '9'){
                System.out.print(9);
                continue;
            }

            if(x.charAt(i)-'0' >= 5)
                System.out.print(9-(x.charAt(i)-'0'));
            else
                System.out.print(x.charAt(i));

       }
        System.out.println("");

   }
}

/*
* @Author: steve
* @Date:   2015-08-20 14:38:04
* @Last Modified by:   steve
* @Last Modified time: 2015-08-20 14:46:53
*/
import java.io.*;
import java.util.*;

public class CandNumber {
    public static void main(String[] args) throws Exception{
    	BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
    	String cad = entrada.readLine();
    	StringBuilder sb = new StringBuilder();
    	for(int i = 0; i<cad.length();i++){
    		int digit = cad.charAt(i)-'0';
    		if(digit > 9-digit)
    			if(9-digit==0 && i==0)
    				sb.append(digit);
    			else
    				sb.append(9-digit);
    		else
    			sb.append(digit);
    	}
    	System.out.println(sb);

    }
}

import java.util.Scanner;

public class no {
	public static void main(String[] args) {

		double count = 0;
		Scanner a = new Scanner(System.in);
		long x = a.nextLong();
		long result = 0;
		if (x != 9) {
			while (x != 0) {
				long no = x % 10;
				long temp = no;
				x = x / 10;
				if (x == 0 && 9 - temp == 0) {
					result =(long)( (long)result + (9) * (Math.pow(10, count)));
				}else {
				if (9 - temp < no) {
					//System.out.println("*****  "+ (9-temp));
					result =(long)( (long)result +(long) ((9 - temp) * (Math.pow(10, count))));
					//System.out.println(result);
				} else {
					//System.out.println("+++++    "+no);
					result = (long)((long)result + (long)((no) * (Math.pow(10, count))));
					//System.out.println(result);
				}
				}
				count++;
			}

			System.out.println((long) result);
		} else {
			System.out.println(9);
		}
	}

}

import java.util.*;
public class ChewbacaAndNumber {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next(),ans="";
		for(int i=0;i<s.length();i++) {
			int a= s.charAt(i) -48;
				a=Math.min(a, 9-a);
				ans+=a;
		}
		if(ans.charAt(0)=='0') {ans=ans.substring(1, ans.length());
		System.out.println("9"+ans);
		}else System.out.println(ans);

	}

}

import java.util.*;

/**
 *
 * @author greggy
 */
public class ChewbaAndNumber {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String mynumber = in.nextLine();
        int[] digits = new int[mynumber.length()];

        for (int i = 0; i < mynumber.length(); i++) {
            char num = mynumber.charAt(i);
            digits[i] = Character.getNumericValue(num);
            if (digits[i] > 4) {
                if (i == 0 && digits[i] == 9) {
                    digits[i] = 9;
                } else {
                    digits[i] = 9 - digits[i];
                }
            }
            System.out.print(digits[i]);
        }
    }
}

import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class TaskA
{
    Scanner in;
    PrintWriter out;
    String n;
    char digits[];

    public static void main(String[] args)
    {
        TaskA mainTest = new TaskA();

        mainTest.readData();
        mainTest.solve();
        mainTest.outputData();
    }

    public TaskA()
    {
        in = new Scanner(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
    }

    public void readData()
    {
        n = in.next();
    }

    public void solve()
    {
        digits = n.toCharArray();

        for (int i = 0; i < digits.length; i++) {
            if (i == 0 && digits[i] == '9') {
                continue;
            }

            if (digits[i] >= '5') {
                digits[i] = (char)(9 - (digits[i] - '0') + '0');
            }
        }
    }

    public void outputData()
    {
        String answerStr = new String(digits);
        long answer = Long.parseLong(answerStr);

        out.println(answer);
        out.flush();
    }
}

import java.io.*;
import java.util.Scanner;

import java.util.StringTokenizer;
/**
 *
 * @author omar
 */
public class Main {

    public static void main(String args[]) throws IOException {
        //BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
      // Scanner in = new Scanner(System.in);
        Reader.init(System.in);

         String s = Reader.next();
         int[] arr = new int [s.length()];
         for (int i = 0; i <s.length(); i++) {
            arr[i]=Integer.parseInt(String.valueOf(s.charAt(i)));
        }
         String neW = "";
         for (int i = 0; i < arr.length; i++) {
            if(arr[i]==9&&i==0)
            {
                neW +=9;
                continue;
            }
            if(arr[i]<5){
                neW+=arr[i];
                continue;
            }
            if(arr[i]>=5){
                neW+=(9-arr[i]);
            }

        }
         System.out.println(neW);

        }
    }

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}

import java.util.*;
public class HelloWorld{

    static int validcount =0;
     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        String str = String.valueOf(n);
        StringBuilder res = new StringBuilder();
        boolean flag = true;
        for(int i=0; i<str.length(); i++) {
            int num = str.charAt(i) - '0';
            if (num != 9)
                flag = false;
            // System.out.println(num);
            if(num < (9-num) || (i==0 && num == 9)) {
                res.append(String.valueOf(num));
            } else {
                res.append(String.valueOf(9 - num));
            }
            // System.out.println(res.toString());
        }
        // if (res.length() == 0)
        //     System.out.println(n);
        // else
        System.out.println(res);
     }

}

import java.util.Scanner;
import java.lang.Math;

public class Chewbacca{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        char[] num = scan.next().toCharArray();
        int index = 0;

        if(num[0] == '9'){
            index = 1;
        }else{
            index = 0;
        }

        for(int i=index;i<num.length;i++){
            int cur = num[i] - '0';

            int val = Math.min(cur, 9-cur);

            num[i] = (char)((char)val+'0');
        }

        System.out.println(num);
    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * Created by Ferrumit on 6/23/2016.
 */
public class _514A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String n = in.next();
        String s = "";
        for (int i = 1; i < n.length(); i++)
            s += ((9 - (n.charAt(i) - '0')) < (n.charAt(i) - '0')) ? (9 - (n.charAt(i) - '0'))+"" : (n.charAt(i) - '0')+"";
        s = (((9 - (n.charAt(0) - '0')) < (n.charAt(0) - '0')) && (9 - (n.charAt(0) - '0')!=0) ?(9 - (n.charAt(0) - '0')) : n.charAt(0)-'0') +""+ s;
        System.out.print((Long.parseLong(n) < Long.parseLong(s)) ? n : s);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mprodev
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AChewbascaAndNumber solver = new AChewbascaAndNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class AChewbascaAndNumber {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong();
            printNumber(x, out);

        }

        public static void printNumber(long x, PrintWriter out) {
            if (x == 0) return;
            long cur = x % 10;
            if (x == 9 && x / 10 == 0) {
                out.print(9);
                return;
            }
            printNumber(x / 10, out);
            out.print(Math.min(cur, 9 - cur));
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Chewbacca_And_Number {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		StringBuilder s = new StringBuilder(t.next());
		int n = s.length();
		StringBuilder ans = new StringBuilder();
		int flag = 0;

		for (int i = 0; i < n; i++) {
			int num = Integer.parseInt(s.substring(i, i + 1));

			if (num >= 5)
				num = 9 - num;

			s.replace(i, i + 1, Integer.toString(num));
		}

		for (int i = 0; i < n; i++) {
			char c = s.charAt(i);

			if (c == '0') {
				if (flag == 0) {

				} else
					ans.append(c);
			} else {
				flag = 1;
				ans.append(c);
			}
		}

		if (ans.length() == 0)
			o.println(9);
		else
			o.println(ans);

		o.flush();
		o.close();

	}

}

import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

public class btp {

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char[] c=s.toCharArray();
		StringBuilder sb=new StringBuilder("");
		for(int i=0;i<c.length;i++){
			int n=c[i]-'0';
			if(9-n<n){
				n=9-n;
				sb.append(n+"");
				//System.out.print(c[i]);
			}
			else{
				sb.append(c[i]);
			}
//			System.out.println(n);
		}
		System.out.println(sb.toString());
		sc.close();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Illidan on 3/20/2016.
 */
public class A514 {
    public static void main(String[] args) throws IOException{
        BufferedReader ip = new BufferedReader(new InputStreamReader(System.in));
        String s = ip.readLine();
        int len = s.length(), tmp;
        int[] n = new int[len];
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len ; i++)
        {
            tmp = Character.getNumericValue(s.charAt(i));
            n[i] = Math.min(tmp, 9-tmp);
        }

        for(int i=0; i<len; i++)
        {
            if(sb.length() == 0) {
                if(n[i] > 0)
                    sb.append(n[i]);
            } else
            {
                sb.append(n[i]);
            }
        }

        if(sb.length() == 0)
            sb.append(0);

        System.out.print(sb);
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        FastPrinter out = new FastPrinter(System.out);
        char[] ch = in.next().toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if(ch[i] > '4'&&ch[i]< '9')
                out.print((char)'9' - ch[i]);
            else
                out.print(ch[i]);
        }
        out.close();
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public BigInteger nextBigInt() {
        return new BigInteger(next());
    }
}

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class CF514A {
    public static void main(String[] args) {
        FastReader input = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);

        String s = input.nextLine();
        boolean first = true;
        boolean done = false;

        for(int i = 0;i < s.length();i++){
            int d = Integer.parseInt(Character.toString(s.charAt(i)));
            if(d <= 4){
                if(d == 0){
                    if(first){

                    }
                    else{
                        pw.print(d);
                        done = true;
                    }
                }
                else{
                    first = false;
                    pw.print(d);
                    done = true;
                }
            }
            else{
                d = 9 - d;
                if(d == 0){
                    if(first){

                    }
                    else{
                        pw.print(d);
                        done = true;
                    }
                }
                else{
                    first = false;
                    pw.print(d);
                    done = true;
                }
            }
        }
        if(!done){
            pw.print(0);
        }

        pw.println();

        pw.flush();
        pw.close();
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class TA {
	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		char[] a=in.nextToken().toCharArray();
		int i,b,n=a.length;
		long ans=0;
		for(i=0;i<n;i++){
			b=a[i]-'0';
			if((9-b)<=4){
				ans=ans*10+(9-b);
			}else{
				ans=ans*10+b;
			}
		}
		if(ans>0)
			System.out.println(ans);
		else
			System.out.println(String.valueOf(a));
	}
	static class FastScanner{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}
		String nextToken(){
			while(st==null||!st.hasMoreElements())
				try{st=new StringTokenizer(br.readLine());}catch(Exception e){}
			return st.nextToken();
		}
		int nextInt(){return Integer.parseInt(nextToken());}
		long nextLong(){return Long.parseLong(nextToken());}
		double nextDouble(){return Double.parseDouble(nextToken());}
	}
}

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char[] s = in.next().toCharArray();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.length; ++i){
            if (Character.getNumericValue(s[i])>4){
                ans.append(9-Character.getNumericValue(s[i]));
            } else {
                ans.append(s[i]);
            }
        }
        out.println(ans);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}

import java.io.*;
import java.util.StringTokenizer;

public class ProblemA {

    private static Scanner in;
    private static Output out;

    public static void solve() throws Exception {
        String line = in.nextLine().replaceAll(" ", "");
        int a[] = new int[line.length()];
        int i = 0;
        for (char c : line.toCharArray()) {
            int v = c - '0';
            if (v >= 5) {
                v = 9 - v;
            }
            a[i++] = v;
        }
        String res="";
        for (i = 0; i < a.length; i++) {
            res+=a[i];
        }
        out.println(Long.parseLong(res));
    }

    public static void main(String[] args) throws Exception {
        initReaderWriter();
        solve();
        out.close();
    }

    private static void initReaderWriter() throws Exception {
        boolean isFile = false;
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

        public Scanner() {
            bf = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class cf1 {
public static void main(String[] args) throws IOException {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String num = bf.readLine();
    for(int i =0; i<num.length(); i++){
        int place = Integer.parseInt("" + num.charAt(i));
        if(place>=5){
            int newNum = 9-place;
            num = num.substring(0, i) + "" + newNum + num.substring(i+1);
        }
    }
boolean starts = true;
for(int i =0; i<num.length() && starts; i++){
    if(num.charAt(i)=='0'){
        num = num.substring(i+1);
        i--;
    }
    else{
        starts = false;
    }
}
System.out.println(num);
}

}

import java.util.*;
public class Learning2 {
	private static int k;
 public static void main(String[] args) {
	 Scanner input = new Scanner(System.in);
     String s1 = input.next();
     String s2 = "";
     int temp;
     for (int i = 0; i < s1.length(); i++) {
    	int c = Character.getNumericValue(s1.charAt(i));
    	if(c>4 && c != 9)
    		s2 += (9-c);
    	else
    		s2 += c;
	 }
     System.out.println(s2);
 }
}

import java.util.*;

public class A {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int tmp;
		for (int i = 0; i < s.length(); i++) {
			tmp = s.charAt(i) - '0';
			if (tmp >= 5)
				tmp = 9 - tmp;
			s = s.substring(0, i) + String.valueOf(tmp) + s.substring(i + 1, s.length());
		}
		System.out.println(s);
	}

}

import java.util.Scanner;

/**
 * Created by zephyr on 2/14/15.
 */
public class Invert {

    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        String input = cin.next();
        StringBuilder sb = new StringBuilder();
        char[] inputArray = input.toCharArray();
        int start = -1;
        for (char digit : inputArray){
            if (digit >= '5'){
                if (start == - 1 && digit == '9') {sb.append('9'); start = 0;}
                else  sb.append('9' - digit);
            }else sb.append(digit);
        }

        long num = (Long.parseLong(sb.toString()));
        if (num != 0){
            System.out.println(num);
        }else{
            System.out.println(9);
        }
    }

}

import java.util.*;
public class A {
	public static void main(String[] args){

		Scanner in = new Scanner(System.in);
		String s = in.next();
//		for(int t = 1; t <= 100; t ++){
//		String s = Integer.toString(t);
		String ans = "";
		for(int i = 0; i < s.length(); i ++){
			ans+= Math.min(9 - (s.charAt(i) - '0'), s.charAt(i) - '0');
		}
		long p = Long.parseLong(ans);
		if(p == 0){
			ans = "9";
			for(int i = 1; i < s.length(); i ++){
				ans+=0;
			}
			p = Long.parseLong(ans);
		}
		System.out.println(p);
//		}
	}
}

import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in  = new Scanner(new BufferedReader(new InputStreamReader((System.in))));
		String str = in.next();
		for(int x = 0; x < str.length(); x++) {
			int c = str.charAt(x) - '0';
			if(c < 9 - c) {
				System.out.print(c);
			}
			else
				System.out.print(9-c);
		}
	}

}

import java.util.Scanner;

public class Solution {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        long num = in.nextLong();
        String result = "";

        if (num > 10)
            while (num != 0) {
                long d = num % 10;
                if (d >= 5&&d!=9) {
                    result = (9 - d) + result;
                } else {
                    result = (d) + result;

                }

                num /= 10;
            }

        else {
            result = num + "";
        }
        System.out.println(result);
    }
}

import java.util.Scanner;
public class Main {
    public static void main(String[] args)
    {
         Scanner in =new Scanner(System.in);
         String x = in.next();
         char [] c = new char [x.length()];
         long [] a = new long [x.length()];
         for(int i=0 ;i<c.length;i++)
         {
             c[i]=x.charAt(i);
         }
         for(int i=0 ;i<c.length;i++)
         {
                int f=Integer.parseInt(c[i]+"");
             if(9-f<f)
                 a[i]=9-f;
             else
             a[i]=f;
         }
         if(a[0]!=0)
         for(int i=0 ;i<a.length;i++)
         {
          System.out.print(a[i]);
         }
         else
          for(int i=1 ;i<a.length;i++)
         {
          System.out.print(a[i]);
         }

    }
}

import java.util.Scanner;

public class hello82 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
//		int smallest = -1;
		int newInt=0;
		int number =1;
		while(n!=0){
			int temp = n %10;

			System.out.println(temp);
			if(temp >=5){
				temp = 9-temp;
			}
			newInt = temp * number + newInt;
			number *=10;
			n/=10;
		}
		if(newInt ==0){
			System.out.println("9");
		}
		else{
			System.out.println(newInt);
		}
	}
}

/*
* @Author: steve
* @Date:   2015-08-20 14:38:04
* @Last Modified by:   steve
* @Last Modified time: 2015-08-20 14:44:10
*/
import java.io.*;
import java.util.*;

public class CandNumber {
    public static void main(String[] args) throws Exception{
    	BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
    	String cad = entrada.readLine();
    	StringBuilder sb = new StringBuilder();
    	for(int i = 0; i<cad.length();i++){
    		int digit = cad.charAt(i)-'0';
    		if(digit > 9-digit)
    			sb.append(9-digit);
    		else
    			sb.append(digit);
    	}
    	System.out.println(sb);

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Mojtaba
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String line=reader.readLine();
        for(int i=0 ; i<line.length() ; i++){
            if(line.charAt(i)>='5'){
                sb.append(('9'-line.charAt(i)));
            }
            else{
                sb.append(line.charAt(i));
            }
        }
        System.out.println(sb.toString().trim());
    }
}

import java.util.*;
import java.io.*;
import java.math.*;

public class test {

static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
	return Long.parseLong(next());
    }

}

 static class Task {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
  		while(testNumber-->0) {
			String num = in.next();
			char[] n = num.toCharArray();
			int len = num.length();
			for(int i=0;i<len;++i) {
				int ch = n[i];
				int ch1 = ('9'-n[i])+48;
				//out.println(" ch = "+ch+" ch1 = "+ch1);
				if(i==0) {
					if(ch1!=0)
						n[i] = (char) Math.min(ch,ch1);
				}
				else
					n[i] = (char) Math.min(ch,ch1);

			}
			out.println(n);

    		}
	}

}

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int test  = 1;
        solver.solve(test, in, out);
        out.close();
    }

}

import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Main test1 = new Main();
		test1.read();
		test1.write();

	}

	private void write() {
		// TODO Auto-generated method stub

	}

	private void read() {
		// TODO Auto-generated method stub
		Scanner fi = new Scanner(System.in);

		String n = fi.next();
		String kq = "";
		while (n.length() != 0) {

			int temp = Integer.valueOf(n.charAt(n.length()-1))-48;
			if ((9 - temp) < temp)
				kq = String.valueOf(9 - temp) + kq;
			else
				kq = String.valueOf(temp) + kq;
			n = n.substring(0, n.length()-1);
//			n /= 10;
		}
		System.out.println(kq);
	}

}

import java.util.Scanner;
public class CDiget {
    public static void main(String[] args) {
        System.out.println(Val());
    }
    public static  int Val()
    {
        Scanner SC = new Scanner(System.in);
        int Num = SC.nextInt();
            int Dig,Res=0,A=1,Chan=9;
    String S;
        S=String.valueOf(Num);

        for(int i =0;i<S.length();i++)
        {
        Dig = S.charAt(i)-48;
        if(Dig>=5)
        {
        Dig = (9-Dig)*A;

        }
        else
        {
            Dig=Dig*A;

        }
          A=A*10;
          Res=Res+Dig;
        }

     return Res;

    }
}

import java.util.*;
public class Main
{
    static void rec(int n)
    {
        if(n==0)
        return;
        rec(n/10);
        if(n%10>=5){
            if(n%10!=9)
        System.out.print(9-(n%10));
            else
            System.out.print(9);
        }
        else
        System.out.print(n%10);
    }
	public static void main(String[] args)
	{
	    Scanner sc=new Scanner(System.in);
	    int i,n,j,s,t,l,k,x1,x2,y1,y2;
	    long max=0l,sum=0l,ans=0l,flag=0l;
	   // float sum=0f;
	   // n=sc.nextInt();
	    n=sc.nextInt();

	   // long ans=0l,ans1=0l,k,h;
	   // int h[]=new int[n];
	   // for(i=0;i<n;i++)
	   // h[i]=sc.nextInt();
	    rec(n);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class test
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new	InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt()
{
return Integer.parseInt(next());
}

long nextLong()
{
return Long.parseLong(next());
}

double nextDouble()
{
return Double.parseDouble(next());
		 }

		String nextLine()
		 {
String str = "";
			 try
			{
				 str = br.readLine();
			 }
			 catch (IOException e)
			 {
				 e.printStackTrace();
			 }
			 return str;
		 }
	 }

	 public static void main(String[] args){
		 FastReader scan=new FastReader();
		  String s = scan.next();
			int[] arr = new int[s.length()];
			boolean onlynine = true;
			for(int i=0;i<s.length();i++){
					int a = Integer.parseInt(s.substring(i,i+1));
					if(a != 9)onlynine = false;
					arr[i] = Math.min(a,9-a);
			}

			if(onlynine == true){
				System.out.print(9);
				for(int i=1;i<arr.length;i++)System.out.print(0);

			}else{
			Arrays.sort(arr);
			if(arr[0] == 0){

				for(int i=1;i<arr.length;i++){
					if(arr[i] != 0){
					 arr[0] = arr[i];
					 arr[i] = 0;
					 break;
					}
				}

			}

			for(int i=0;i<arr.length;i++)System.out.print(arr[i]);

		}

		}
}

import java.util.Scanner;

public class Solution {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        long num = in.nextLong();
        String result = "";

        if (num > 10)
            while (num != 0) {
                long d = num % 10;
                if (d >= 5) {
                    result = (9 - d) + result;
                } else {
                    result = (d) + result;

                }

                num /= 10;
            }

        else {
            result = num + "";
        }
        System.out.println(result);
    }
}

    import static java.lang.System.exit;
    import java.util.ArrayList;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Scanner;
    import java.util.*;
    /**
     *
     * @author abdelmagied
     */
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.HashMap;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import java.util.Scanner;

public class JavaApplication1 {

      public static void main(String[] arg){
          Scanner sc = new Scanner(System.in);

          String nextVal = sc.next();

          StringBuilder str = new StringBuilder(nextVal);

          for(int i = 0 ; i < str.length() ; i++){
              int v = Character.getNumericValue(str.charAt(i));
              int vv =  Integer.min(v , 9-v);
              if(vv == 0 && i != 0)
              str.setCharAt(i, (char)(vv+48));
          }
          System.out.println(str.toString());
      }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String n = scan.nextLine();
        char[] wow = {'9','8','7','6','5'};
        StringBuilder gg = new StringBuilder(n);
        for (int i = 0; i < n.length(); i++) {
            int temp = Arrays.binarySearch(wow, n.charAt(i));
            if (temp > -1) {
                gg.setCharAt(i, (temp + "").charAt(0));
            }
        }
        System.out.println(gg + "");
    }
}

//package codeforces150214;

import java.util.Scanner;

public class a1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String out = "";
        for (int i = 0; i < str.length(); i++) {
            int now = Integer.parseInt(str.substring(i, i + 1));
            if (now > 4) {
                now = 9 - now;
                out = out + "" + now;
            } else {
                out = out + "" + now;
            }
        }
        if (Integer.parseInt(out.substring(0, out.length())) == 0) {
            out = "9" + out.substring(1, out.length());
        }
        System.out.println(out);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Mojtaba
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String line = reader.readLine();

        for (int i = 0; i < line.length(); i++) {
            if (i == 1) {
                if (line.charAt(i) == '9') {
                    sb.append("9");
                }
            }
            if (line.charAt(i) >= '5') {
                sb.append(('9' - line.charAt(i)));
            } else {
                sb.append(line.charAt(i));
            }
        }
        System.out.println(sb.toString().trim());
    }
}

import java.io.*;
import java.util.*;

public class Solution{

	public static void main(String [] args){

		Scanner s = new Scanner(System.in);

		long n = s.nextLong();

		long res = 0;
		long fact = 1;

		while(n!=0){
			long r = n%10;

			if(r>=5 && n/10!=0)
				res += fact*(9-r);
			else
				res += fact*r;

			n/=10;
			fact *= 10;
		}

		System.out.println(res);
	}

}

import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

           Scanner  in = new Scanner(System.in);

           StringBuilder OX = new StringBuilder(in.next());
           StringBuilder NX = new StringBuilder();

           for (int i = 0; i < OX.length(); i++) {

               if((9-(OX.charAt(i)-'0')) < (OX.charAt(i)-'0'))
               {
                 NX.append((9-(OX.charAt(i)-'0')));
               }
               else
               {
               NX.append(OX.charAt(i));
               }

        }

           System.out.println(NX);
    }

}

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Sheet_A {

	public static boolean goodNumber(String num, int k) {

		for (char i = '0'; i <= '0' + k; i++)
			if(num.indexOf(i) == -1)
				return false;
		return true;
	}

	public static boolean isPrime(long n) {

		for (long i = n / 2; i >= 2; i--)
			if (n % i == 0)
				return false;
		return true;
	}

	public static boolean isCoPrime(long a, long b) {

		if (isPrime(a) && b % a != 0 || isPrime(b) && a % b != 0)
			return true;
		return false;

	}

	public static boolean isValid(int a1, int r1, int c1, int d1) {
		return (r1 - a1 <= 9 && r1 - a1 > 0 && c1 - a1 <= 9 && c1 - a1 > 0 && d1 - a1 <= 9 && d1 - a1 > 0 &&  a1 != d1 - a1 && a1 != c1 - a1 && a1 != r1 - a1 && r1 - a1 != d1 - a1 && r1 - a1 != c1 - a1 && d1 - a1 != c1 - a1);
	}

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		String word = input.next();
		int i;
		String ans = "";
		if (word.charAt(0) - 48 == 9) {
			ans += 9;
			i = 1;
		}
		else
			i = 0;

		for (; i < word.length(); i++) {
			int val = word.charAt(i) - 48;

			ans = ((val < 9 - val) ? val : 9 - val) + ans;
		}

		System.out.println(ans);

	}

}

/*
int arr[] = new int[n];
for (int i = 0; i < n; i++)
arr[i] = input.nextInt();
*/

//Arrays.sort(arr);

/*for (int i = 0; i < n; i++)
System.out.print(arr[i] + " ");
*/

/*
 * int n = input.nextInt();
	int t = input.nextInt();

	int k = (int) ((Math.pow(10 % t, n) % t) * -1 + 12);

	System.out.print(k + Math.pow(10, n));

 */

import java.util.ArrayList;
import java.util.Scanner;

/**","* Created by Daniil on 13.08.2014.","*/
public class Main {

    public static void main(String args[]) {

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        ArrayList<Character> characters = new ArrayList<>();

        for (char c : s.toCharArray()) {
            characters.add(process(c));
        }
        try {
            while (characters.get(0) == '0')
                characters.remove(0);
        }
        catch  (IndexOutOfBoundsException e) {
                characters.add('0');
            }
        for (Character c : characters)
            System.out.print(c);

    }

    static char process(char c) {
        switch (c) {
            case '0' : return '0';
            case '1' : return '1';
            case '2' : return '2';
            case '3' : return '3';
            case '4' : return '4';
            case '5' : return '4';
            case '6' : return '3';
            case '7' : return '2';
            case '8' : return '1';
            default : return '0';

        }
    }
}

import java.util.HashMap;
import java.util.Scanner;

public class CR126B {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String x=sc.next(),res="";
        HashMap<Integer,Integer> values=new HashMap<>();
        for (int i = 0; i < 10; i++) {
            if (i<5)values.put(i,i);
            else values.put(i,9-i);
        }
        if (x.charAt(0)=='9')res+='9';
        for (int i = 1; i < x.length(); i++)
            res+=values.get(Integer.parseInt(""+x.charAt(i)));
        System.out.print(res);
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution{
	public void init(){
		Scanner scan = new Scanner(System.in);
		String input = scan.nextLine();
		char[] digits = input.toCharArray();
		int i = 0;
		while(i < digits.length - 1 && digits[i] == '9')
			i++;
		for(; i < digits.length; i++){
			if(digits[i] >= '5'){
				digits[i] = (char)('0' + (9 - (digits[i] - '0')));
			}
		}
		System.out.println(new String(digits));
		scan.close();
	}

	public void solve(){

	}
	public static void main(String[] args){
		Solution tool = new Solution();
		tool.init();
		tool.solve();
	}
}

import java.util.Scanner;
public class Main {
    public static void main(String[] args)
    {
         Scanner in =new Scanner(System.in);
         String x = in.next();
         char [] c = new char [x.length()];
         long [] a = new long [x.length()];
         for(int i=0 ;i<c.length;i++)
         {
             c[i]=x.charAt(i);
         }
         for(int i=0 ;i<c.length;i++)
         {
                int f=Integer.parseInt(a[i]+"");
             if(9-f<f)
                 a[i]=9-f;
         }
         if(a[0]!=0)
         for(int i=0 ;i<a.length;i++)
         {
          System.out.print(a[i]);
         }
         else
          for(int i=1 ;i<a.length;i++)
         {
          System.out.print(a[i]);
         }

    }
}

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char[] s = in.next().toCharArray();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.length; ++i){
            if (Character.getNumericValue(s[i])>4){
                int temp = 9-Character.getNumericValue(s[i]);
                if (temp!=0) ans.append(temp);
                else if (ans.length()>0) ans.append(temp);
            } else {
                ans.append(s[i]);
            }
        }
        if (ans.length()>0)out.println(ans);
        else out.println('0');
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}

import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;

public class Main
{

            public static void main(String[] args)
            {

                    FastInput input = new FastInput(System.in);
                    PrintWriter output = new PrintWriter(System.out,true);

                    long x =input.readLong();
                    StringBuilder num =new StringBuilder(""+x);

                    for(int i=0;i<num.length();++i)
                    {
                            if(num.charAt(i)>='5' && num.charAt(i)<='9')
                                num.setCharAt(i, (char)('9'- num.charAt(i)+'0'));

                    }

                    long newnum =Long.parseLong(num.toString());

                    if(newnum == 0)
                    {
                            long power = 1;

                            while(x%10 == 0)
                            {
                                x=x/10;
                                power = power*10;
                            }

                            newnum = (x%10)*power;

                    }

                    output.println(newnum);

                    input.close();
                    output.close();

            }
}

class FastInput
{

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastInput(InputStream userInputStream)
        {
            this.stream = userInputStream;

        }

        public int readChar()
        {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {

                curChar = 0;

                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;

            }

            return buf[curChar++];

        }

        public boolean isSpaceChar(int c)
        {

                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;

        }

        public int readInt()
        {

            int c = readChar();
            int sgn = 1;

            while (isSpaceChar(c))
                c = readChar();

            if (c == '-' )
            {
                sgn = -1;
                c = readChar();

            }

            int res = 0;

            do {

                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = readChar();

            } while (!isSpaceChar(c));

            return res * sgn;

        }

        public long readLong()
        {

            int c = readChar();
            int sgn = 1;

            while (isSpaceChar(c))
                c = readChar();

            if (c == '-' )
            {
                sgn = -1;
                c = readChar();

            }

            long res = 0;

            do {

                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = readChar();

            } while (!isSpaceChar(c));

            return res * sgn;

        }

        public String readString() {

            int c = readChar();

            while (isSpaceChar(c))
                c = readChar();

            StringBuilder res = new StringBuilder();

            do
            {

                res.append((char)c);
                c = readChar();

            } while (!isSpaceChar(c));

            return res.toString();

        }

        // The method created intially skips all whitespaces as defined above and then starts reading everything before \r , \n  , or both
        public String readLine()
        {
                int c=  readChar();

                while (isSpaceChar(c))
                    c = readChar();

                StringBuilder res = new StringBuilder();

                do
                {
                    res.append(c);
                    c = readChar();

                }while (c != '\r' &&  c!= '\n');

                return res.toString();

        }

        public void close()
        {
                try
                {
                    stream.close();
                }
                catch(IOException ex)
                {
                    ex.printStackTrace();

                }
        }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C512A {
	private StringTokenizer st;
	private BufferedReader bf;
	public C512A() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());

			String s = next();
			int n = s.length();
			char[] a = s.toCharArray();
			char[] ans = new char[n];
			int index = 0;
//			if (n == 1) {
//				System.out.println((9-Character.getNumericValue(a[0])));
//				return;
//			}

			boolean change = false;
			boolean nonine = false;
			for(int i = 0; i < n; i++) {
				int k = Character.getNumericValue(a[i]);
				int u = 9 - k;
				if (k != 9) {
					nonine = true;
				}
				if (u < k && nonine) {
					change = true;
					ans[i] = Integer.toString(u).charAt(0);
				} else {
					ans[i] = Integer.toString(k).charAt(0);
				}
			}
//			if (!change) {
//				int k = Character.getNumericValue(a[n - 1]);
//				int u = 9 - k;
//				ans[n - 1] = Integer.toString(u).charAt(0);
//			}

//			String r = "";
//			for(int i = 0; i < n; i++) {
//				index = 0;
//				char[] t = new char[n];
//				for(int j = 0; j < i; j++) {
//					t[index] = a[j];
//					index++;
//				}
//				for(int j = i; j < n; j++) {
//					int k = Character.getNumericValue(a[j]);
//					int u = 9 - k;
//					t[index] = Integer.toString(u).charAt(0);
//					index++;
//				}
//				if (ans[0] == 0x0) {
//					for(int k = 0; k < n; k++) {
//						ans[k] = t[k];
//					}
//				} else {
//					for(int m = 0; m < n; m++) {
//						if (ans[m] > t[m]) {
//							for(int k = 0; k < n; k++) {
//								ans[k] = t[k];
//							}
//							break;
//						}
//					}
//				}
//			}

			//skip leading zero
			int pos = 0;
			for (int i = 0; i < ans.length; i++) {
				if (ans[i] == '0')
					pos++;
				else
					break;
			}
			if (pos == s.length()) {
				System.out.println(0);
				return;
			}
			String ss = new String(ans);
			System.out.println(ss.substring(pos, ss.length()));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		C512A c = new C512A();
	}

}

import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new InputStreamReader(System.in));
        long number = in.nextLong();

        long output = 0;
        long index = 1;
        while (number > 0) {
            int cur = (int) number % 10;

            if (cur >= 5) {
                output += (9 - cur) * index;
            } else{
                output += cur * index;
            }

            number /= 10;
            index *= 10;
        }
        System.out.println(output);
    }

}

import java.util.Scanner;

public class no {
	public static void main(String[] args) {

		double count = 0;
		Scanner a = new Scanner(System.in);
		long x = a.nextLong();
		double result = 0;
		if (x != 9) {
			while (x != 0) {
				long no = x % 10;
				long temp = no;
				x = x / 10;
				if (x == 0 && 9 - temp == 0) {
					result = result + (9) * (Math.pow(10, count));
				}else {
				if (9 - temp < no) {
					result = result + (9 - temp) * (Math.pow(10, count));
				} else {
					result = result + (no) * (Math.pow(10, count));
				}
				if (x == 0 && 9 - temp == 0) {

				}
				count++;
				}
			}

			System.out.println((int) result);
		} else {
			System.out.println(9);
		}
	}

}

import java.util.*;
public class Main {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String s = in.next();
        int min = Integer.MAX_VALUE ;
        for (int i=0 ; i<s.length() ; i++)
        {
            if (Integer.parseInt(s.charAt(i)+"")<min)
            {
                min = Integer.parseInt(s.charAt(i)+"");
                break ;
            }
        }
        for (int i=0 ; i<s.length() ; i++)
        {
            if (min==0&&(i==s.length()-1)) {}
            else System.out.print(min);
        }
  }
}

import java.util.*;
public class A514
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int n1=0;
if(n!=0)
{
while(n>0)
{
int a=n%10;
if(a>=5)
a=9-a;
n1=n1*10+a;
n=n/10;
}
System.out.println(n1);
}
else
System.out.println("9");
}
}

//package SRM291;

import java.io.*;

public class R291A {

    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(isr);

        String linea;

        char[] Datos;
        String Num = "";

        int digit, inverted;

        while((linea = in.readLine()) != null && linea.length() != 0){
            Datos = linea.toCharArray();

            Num = "";
            for (int i = 0; i < Datos.length; i++) {
                digit = Character.getNumericValue(Datos[i]);
                inverted = 9 - Character.getNumericValue(Datos[i]);

                if (inverted < digit) Num += inverted;
                else Num += digit;
            }

            boolean flag9 = false;
            for (int i = 0; i < Num.length(); i++) if (Byte.valueOf(Num.substring(i,i + 1)) != 9) flag9 = true;

            if (flag9) Num ="";
            else {
                while (true) {
                    if (Num.substring(0, 1).compareTo("0") == 0) Num = Num.substring(1);
                    else break;
                }
            }
            System.out.println(Num);
        }
    }

}

import java.util.Scanner;
public class Name {
	public Name (){
		Scanner stream = new Scanner (System.in);
		long x = stream.nextLong() ;
		method (x);
	}
	public void method (long x){
		String num = String.valueOf(x);
		for (int i = num.length()-1 ; i >=0 ; i--){
			String newN = num.substring(0, i)+ (9-num.charAt(i)+48) + num.substring(i+1, num.length());
			if (Long.parseLong(newN) < Long.parseLong(num) ){
				num = newN ;
			}
		}
		System.out.println(Long.parseLong(num));
	}
	public static void main (String [] args){
		new Name ();
	}
}

import java.util.*;
public class first
{

	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		String s = new String(input.next());
		StringBuilder changed = new StringBuilder(s);
		boolean b = true;
		for(int i =0; i < s.length(); i++)
			if(s.charAt(i) != '9')
				b = false;

//		if(!b){

		for(int i =0; i < s.length(); i++)
		{
			if(( '9'- changed.charAt(i) +'0') < changed.charAt(i) )
			{
				//System.out.println(s.charAt(i));
				changed.setCharAt(i, (char) ( '9'- s.charAt(i)+'0'));
			}
		}

		System.out.println(Long.parseLong(changed.toString()));
//	}
//		else
//		{
//			System.out.println(9);
//		}
		}

}

import java.io.*;
public class chewbacca
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,d,f,n;
  d=f=0;
  String s;
  s=in.readLine();
  n=s.length();
  for(i=0;i<n;i++)
  {
   d=Integer.parseInt(s.substring(i,i+1));
   if(d>=5 && d<=8)
   {
    s=s.substring(0,i)+(char)(57-d)+s.substring(i+1);
    f=1;
   }
   else if(d==9 && f==1)
   s=s.substring(0,i)+(char)(57-d)+s.substring(i+1);
  }
  System.out.println(s);
 }
}

import java.util.Scanner;

public class Main{
    private static String InvertDigitAt(int dig_index, String number){
        String invert_number = "", digit;
        for(int index = 0; index < number.length(); index++){
            digit = "" + number.charAt(index);
            if(index == dig_index && 9 - Integer.parseInt(digit) < Integer.parseInt(digit))
                invert_number += 9 - Integer.parseInt(digit);
            else invert_number += digit;
        }
        return invert_number;
    }

    private static String MinInvertNumber(String number){
        for(int index = number.length() - 1; index > 0; index--){
            if(index == 0 && InvertDigitAt(index, number).charAt(index) != '0')
                number = InvertDigitAt(index, number);
            else number = InvertDigitAt(index, number);
        }
        return number;
    }

    public static void Solve() {
        Scanner scanner = new Scanner(System.in);
        System.out.println(MinInvertNumber(scanner.nextLine()));
    }

    public static void main(String[] args){
        Solve();
    }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{//ChewbaccaAndNumber{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();

		String line = in.next();
		if(line.length()==1){
			System.out.println(line);

		}else{
		char[] l = line.trim().toCharArray();

		int min = Integer.parseInt(""+l[0]);
		for(int i =1;i<l.length;i++){
			min = Math.min(min, Integer.parseInt(""+l[i]));
		}

		for(int i =0;i<l.length;i++){

		 if((""+l[i]).equals(""+0) || (""+l[i]).equals(""+1) ||
					(""+l[i]).equals(""+2) || (""+l[i]).equals(""+3)|| (""+l[i]).equals(""+4)){
				list.add(Integer.parseInt(""+l[i]));
			}
			else {
				int b = 9- Integer.parseInt(""+l[i]);
				list.add(b);
			}
		}
		for(int i =0;i<list.size();i++){
			System.out.print(list.get(i));
		}
		System.out.println();
	}
		}
}

import java.io.*;
import java.util.*;

public class A
{
    static int n;
    static int[] arr;
    static char[] s;
    public static void main(String[] args) throws IOException
    {
        Flash f = new Flash();
        s = f.ns().toCharArray();
        sop(fn());
    }

    static String fn()
    {
        n = s.length;
        if(n == 1 && s[0] == '9') return "0";
        char[] ans = new char[n];
        if(s[0] != '9'){
            ans[0] = s[0];
            int num = s[0] - '0';
            if(num >= 5) num = 9-num;
            ans[0] = (char)(num+48);
        }

        for(int i = 1; i < n; i++){
            ans[i] = s[i];
            int num = s[i] - '0';
            if(num >= 5) num = 9-num;
            ans[i] = (char)(num+48);
        }

        return new String(ans);
    }

    static void sort(int[] a){
        List<Integer> A = new ArrayList<>();
        for(int i : a) A.add(i);
        Collections.sort(A);
        for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
    }

    static int swap(int itself, int dummy){
        return itself;
    }

    static void sop(Object o){ System.out.println(o); }

    static void print(int[] a){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
        System.out.println(sb);
    }

    static class Flash
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next(){
            while(!st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        String ns(){
            String s = new String();
            try{
                s = br.readLine().trim();
            }catch(IOException e){
                e.printStackTrace();
            }

            return s;
        }

        int ni(){
            return Integer.parseInt(next());
        }

        int[] arr(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

        long nl(){
            return Long.parseLong(next());
        }

        double nd(){
            return Double.parseDouble(next());
        }
    }
}

import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		char[] s = new char[24];
		Scanner sc = new Scanner(System.in);
		s = sc.nextLine().toCharArray();
		for (int i = 0; i < s.length; ++i) {
			if (s[i] >= '5') {
				s[i] = (char) ('9' - s[i] + '0');
			}
		}
		long a = Long.valueOf(String.copyValueOf(s));
		if(a==0){
			a=9;
		}
		System.out.println(a);
	}
}

//package codeforcesround.2015.round291;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class ChewbaccaAndNumber {
        BufferedReader br; PrintWriter out; StringTokenizer tk; boolean eof, submit;
        public static void main(String args[]) throws IOException { new ChewbaccaAndNumber(); }

        String ntk() { while (tk == null || !tk.hasMoreTokens()) { try { tk = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return null; } } return tk.nextToken(); }
        String nln() { try { return br.readLine(); } catch (IOException e) { eof = true; return null; } }
        String ns() { return ntk(); }
        int ni() throws IOException { return Integer.parseInt(ntk()); }
        long nl() throws IOException { return Long.parseLong(ntk()); }
        float nf() throws IOException { return Float.parseFloat(ntk()); }
        double nd() throws IOException { return Double.parseDouble(ntk()); }
        void debug(Object... o) { if(!submit) { System.out.println(Arrays.deepToString(o)); } }

        public ChewbaccaAndNumber() throws IOException {
                long start = System.currentTimeMillis();
                submit = !false;
                if(submit == false) br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\input.txt")));
                else br = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);

                int T = 1; while(T-- > 0) solve();

                long end = System.currentTimeMillis();
                debug(end - start, " ms");
                out.close();
        }

        String X;
        void solve() throws IOException {
                X = nln();
                StringBuilder sb = new StringBuilder();
                for(int i=0; i<X.length(); i++) {
                        int value = Integer.parseInt(X.charAt(i)+"");
                        if(value >= 5) {
                                value = 9 - value;
                        }
                        sb.append(value);
                }
                while(sb.charAt(0) == '0') {
                        sb.deleteCharAt(0);
                        if(sb.length() == 0)
                                break;
                }
                if(sb.length() > 0)
                        out.println(sb.toString());
                else {
                        if(X.charAt(X.length()-1) != '9') {
                                int value = X.charAt(X.length()-1);
                                if(value >= 5)
                                        value = 9 - value;
                                out.println(value);
                        } else {
                                out.println("9");
                        }
                }
        }
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] c1 = s.nextLine().toCharArray();
        char[] c2 = new char[c1.length];
        char[] c3 = new char[c1.length];
        for(int i = 0; i < c1.length; i++) {
            c2[i] = (char)('0' + '9' - c1[i]);
            c3[i] = (char)Math.min((int)c1[i], (int)c2[i]);
        }
        String str = "";
        for(int i = 0; i < c1.length; i++) {
            str += c3[i];
        }
        System.out.print(Integer.parseInt(str));
    }
}

import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    String a = scan.next();
    if (a == "9") {
      System.out.println(a);
    } else {
    String build = "";
    for (int i =0; i < a.length(); i++) {
      char curChar = a.charAt(i);
      if (curChar > '4') {
        build = build + (char)(('9'-curChar)+48);
      } else {
        build = build + curChar;
      }
    }
    System.out.println(Long.valueOf(build));
    }
  }
}

import java.util.*;
/**
 * Write a description of class NúmeroyChewbaсca here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Main
{
   public static void main(String [] arg)
   {
    Scanner lector= new Scanner(System.in);
    long num= lector.nextLong();
    long res=0;
    while(num != 0)
    {
        long aux= num % 10;
      if(num>=0 && num<=9)
      {
        if(9-aux==0)
        {
         aux= aux;
        }
      }
      else if(9-aux < aux)
      {
        aux= 9-aux;
      }
      res= res*10 + aux;
      num= num/10;
    }
    res= invertir(res);
    System.out.println(res);
   }
   private static long invertir(long n)
   {
     long res=0;
     while(n!=0)
     {
       long aux= n%10;
       res= res*10 + aux;
       n= n/10;
     }
     return res;
   }
}

import java.util.*;

public class Chewy {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    char[] line = input.nextLine().toCharArray();
    for (int i = 0; i < line.length; i++) {
      int j = Character.getNumericValue(line[i]);
      if (j > 4 && (j != 9 && i == 0)) {
        j = 9 - j;
        line[i] = (char)(j + '0');
      }
    }
    StringBuilder sb = new StringBuilder();
    for (char c : line) {
      sb.append(c);
    }
    System.out.println(Integer.parseInt(sb.toString()));
  }
}

 import java.util.*;
public class NewClass1 {

    public static void main(String [] args)
    {

        Scanner in=new Scanner(System.in);
       String s=in.next();
       for(int i=0;i<s.length();i++)
         {
              String d=""+s.charAt(i);
             int y=Integer.parseInt(d);

       System.out.print((y>4)?(9-y):y);

       }

}}

import java.util.Scanner;

/**
 * Created by zephyr on 2/14/15.
 */
public class Invert {

    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        String input = cin.next();
        StringBuilder sb = new StringBuilder();
        char[] inputArray = input.toCharArray();
        for (char digit : inputArray){
            if (digit >= '5'){
                sb.append('9' - digit);
            }else sb.append(digit);
        }

        System.out.println(Long.parseLong(sb.toString()));
    }

}

import java.util.Scanner;

public class DIV291A {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		 int n = sc.nextInt();

		 String s = Integer.toString(n);
		 String ss = "";
		 for(int i=0;i<s.length();i++){
			 Character ch = s.charAt(i);
			 if(i==0 && ch == '9' || (Integer.numberOfLeadingZeros(n) >0 )){
				 System.out.println(n);
				 return;
			 }
			 if (Integer.parseInt(Character.toString(ch)) >= 5 ){
				 ss += Integer.toString(9 - Integer.parseInt(Character.toString(ch)));
			 }else{
				 ss+=ch;
			 }
		 }

		 System.out.println(ss);
	}

}

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
     	Scanner sc = new Scanner(System.in);
     	String s = sc.next();
     	StringBuilder sb = new StringBuilder("");
     	int  n1= s.length();
     	for(int i=0;i<n1;i++){
     		int n = (int)s.charAt(i)-48;
     		if(n>4){
     			n = 9 -n;
     		}
     		sb.append(n+"");
     	}
     	System.out.println(sb);

    }
}

import java.util.Scanner;

public class problema {

	public static void main(String[] args) {
	Scanner myscanner=new Scanner(System.in);
	String x=myscanner.next();
      int[] result=new int[34];
      int count=0;
	for(int i=0;i<x.length();i++)
	{
		if(x.charAt(i)>='5'&&x.charAt(i)<'9')
		result[count++]=9-(x.charAt(i)-48);
		else
		result[count++]=(x.charAt(i)-48);

	}
	int i;
	for( i=0;i<count;i++){
		if(result[i]>0)
			break;
	}
	for(int j=i;j<count;j++)
		System.out.print(result[j]);
	System.out.println();

	}

}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        String s=in.next();
        String o = new String();
        for (int i=0;i<s.length();i++){
            int x=Character.getNumericValue(s.charAt(i));
            if (x>4&&x<9 ){
x=9-x;
o+=String.valueOf(x);
            }
             else o+=(String.valueOf(x));

        }

System.out.println(o);

	// write your code here
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        FastPrinter out = new FastPrinter(System.out);
        char[] ch = in.next().toCharArray();
        if(ch[0] > '4'&&ch[0]<9)
            out.println((char)'9' - ch[0]);
        else
            out.print(ch[0]);
        for (int i = 1; i < ch.length; i++) {
            if(ch[i] > '4')
                out.print((char)'9' - ch[i]);
            else
                out.print(ch[i]);
        }
        out.close();
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public BigInteger nextBigInt() {
        return new BigInteger(next());
    }
}

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}

import java.util.*;
public class ChewbaccaAndNumber {
	public static void main(String[] args) {
		Scanner x=new Scanner(System.in);
		long n=x.nextLong();
		String p=n+"";
		ArrayList<Integer>n2=new ArrayList<Integer>();
		for (int i = 0; i < p.length(); i++) {
			if(9-(p.charAt(i)-'0')<(p.charAt(i)-'0') && p.length()>1){
				n2.add(9-(p.charAt(i)-'0'));
			}
			else
			n2.add((p.charAt(i)-'0'));
		}
		Collections.sort(n2);
		int min=n2.get(0);
		int secondMin=0;
		if(n2.size()>1){
		secondMin=n2.get(1);
		}
		String m="";
		if(min==0 && n2.size()>1){
			m+=secondMin;
			for (int i = 0; i < p.length()-1; i++) {
				m+=min;
			}
			System.out.println(m);
		}
		else{
			m+=min;
			for (int i = 0; i < p.length()-1; i++) {
				m+=secondMin;
			}
			System.out.println(m);
		}

	}

}

import java.util.*;
public class xyz {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	long x=sc.nextLong();

	String y=Integer.toString((int)x);
	long arr[]=new long[y.length()];
	long t=0;
	for(long i=0;i<y.length();i++){
		arr[(int) i]=y.charAt((int) i)-'0';
		t=Integer.parseInt(y.substring((int)i,(int)i+1));
		if(t>=5)
			{t=9-t;}
		if(i==0&&t==0)
		{}
		else System.out.print(t);
	}

	}

}

import java.io.*;
import java.util.StringTokenizer;

public class ProblemA {

    private static Scanner in;
    private static Output out;

    public static void solve() throws Exception {
        String line = in.nextLine().replaceAll(" ", "");
        int a[] = new int[line.length()];
        int i = 0;
        for (char c : line.toCharArray()) {
            int v = c - '0';
            if (v >= 5) {
                v = 9 - v;
            }
            a[i++] = v;
        }
        for (i = 0; i < a.length; i++) {
            out.print(a[i]);
        }
        out.println();
    }

    public static void main(String[] args) throws Exception {
        initReaderWriter();
        solve();
        out.close();
    }

    private static void initReaderWriter() throws Exception {
        boolean isFile = false;
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

        public Scanner() {
            bf = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return bf.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }
}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**
 *
 * @author Solution by: L.Azuaje.
 *
 * Codeforces: 514A.  Round #291 (Div. 2). 	Chewba�?ca and Number.
 *
 */

public class Main {

	public String find(String string) {
		char[] data = string.toCharArray();
        char nine = '9';
        String solution = "";

		for (int i = 0; i < data.length; i++) {
			if ( nine  - data[i] < data[i] - '0' &&  nine  - data[i] != 0) {
                solution  +=  (nine  - data[i]);
			} else {
                solution += data[i];
            }
		}

		return solution;
	}

	public static void main(String[] args) throws IOException {
		MyScanner scanner = new MyScanner();
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

		Main main = new Main();

		String string = scanner.next();

		out.println(main.find(string));

		scanner.reader.close();
		out.close();
	}

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader reader;

		public MyScanner() {
			this.reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public void close() throws IOException {
			this.reader.close();
		}

		int nextInt() {
			return Integer.parseInt(this.next());
		}

		long nextLong() {
			return Long.parseLong(this.next());
		}

		double nextDouble() {
			return Double.parseDouble(this.next());
		}

		String next() {
			String str = "";
			try {
				str = this.reader.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
}

import java.util.Scanner;
public class Solution_1 {
    public static void main(String args[])
    {
        Scanner input=new Scanner(System.in);
        long num=input.nextLong(),n=0l,a=1l,p;
        p=num;
        while(num>0)
        {
            if(num%10>=5)
            {
                n=n+((9-(num%10))*a);

            }
            else
            {
                n=n+((num%10)*a);
            }
            a*=10;
            num/=10;
        }
        if(n!=0)
        System.out.println(n);
        else
            System.out.println(p);

    }

}

import java.util.*;
public class HelloWorld{

    static int validcount =0;
     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        String str = String.valueOf(n);
        StringBuilder res = new StringBuilder();
        for(int i=0; i<str.length(); i++) {
            int num = str.charAt(i) - '0';
            // System.out.println(num);
            if(num < (9-num)) {
                res.append(String.valueOf(num));
            } else {
                res.append(String.valueOf(9 - num));
            }
        }
        System.out.println(res.reverse());
     }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C512A {
	private StringTokenizer st;
	private BufferedReader bf;
	public C512A() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());

			String s = next();
			int n = s.length();
			char[] a = s.toCharArray();
			char[] ans = new char[n];
			int index = 0;
			if (n == 1) {
				System.out.println((9-Character.getNumericValue(a[0])));
				return;
			}

			for(int i = 0; i < n; i++) {
				int k = Character.getNumericValue(a[i]);
				int u = 9 - k;
				if (u < k) {
					ans[i] = Integer.toString(u).charAt(0);
				} else {
					ans[i] = Integer.toString(k).charAt(0);
				}
			}

			int pos = 0;
			for (int i = 0; i < ans.length; i++) {
				if (ans[i] == '0')
					pos++;
				else
					break;
			}
			if (pos == s.length()) {
				System.out.println(0);
				return;
			}
			String ss = new String(ans);
			System.out.println(ss.substring(pos, ss.length()));

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		C512A c = new C512A();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;

		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

}

class TaskD {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
	}

}

class TaskA {

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		String number = in.next();
		StringBuffer result = new StringBuffer();
		for(int i=0;i<number.length();++i){
			char ch = number.charAt(i);
			result.append(invert(ch));
		}
		while(result.length()>1&&result.charAt(0)=='0'){
			result.deleteCharAt(0);
		}
		if(result.length()==1&result.charAt(0)=='0'){
			out.println("9");
			return;
		}
		out.println(result.toString());
	}

	private char invert(char ch) {
		if(ch>'4'){
			ch -='0';
			int r = 9-(int)ch;
			return (char)('0'+r);
		}
		return ch;
	}

}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter out)
			throws IOException {
	}

}

class TaskC {

	public void solve(int testNumber, InputReader in, PrintWriter out) {

	}

}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Test
{
	public static void main(String[] args) throws Exception
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int data = 0;
		boolean firstNumber = false;
		while((data = in.read()) != -1)
		{
			if(data == 13)
				return;

			data -= 48;
			if(data >= 5)
				data = 9 - data;
			if(data == 0 && firstNumber)
				System.out.print(data);
			else
			{
				System.out.print(data);
				firstNumber = true;
			}
		}

		in.close();
}
}

import java.util.Scanner;

public class _514A_ {
    public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	char[] s = in.next().toCharArray();
	for (int i = 0; i < s.length; i++)
	    if (s[i] > 0x34)
		s[i] = (char) (0x39 - s[i] + 0x30);
	long ans2 = Long.valueOf(new String(s));
	System.out.println(ans2);
    }

}

import java.util.*;

public class A514 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        int[] c = new int[n.length()];
        for(int i = 0; i < n.length(); i++){
            c[i] = Integer.parseInt(n.charAt(i)+"");
        }

        String res = ""+c[0];
        for(int i = 1; i < n.length(); i++){
            if(c[i] >= 5){
                c[i] = 9-c[i];
                res += c[i];
            }else {
                res += c[i];
            }
        }
        System.out.println(Integer.parseInt(res));

    }
}

import java.util.Scanner;

public class main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long divideNum = 10 , tempnum , result = 0;
		long num = s.nextLong();
		while (num > 0 ) {
			tempnum = num % 10;
			num = num /10;
			if(tempnum < 5 ) {
				result += tempnum * divideNum;
			}
			else if (tempnum >= 5 ) {
				if(tempnum == 9 && num == 0) {
					result += tempnum * divideNum;
				}
				else {
				result += (9-tempnum) * divideNum;
				}
			}

			divideNum = divideNum*10;
		}

		System.out.println(result/10);
	}
}

import java.util.*;
public class test{
           public static void main(String [] args){
                      Scanner scan=new Scanner(System.in);
                      int x=scan.nextInt();int d=0;
                      int temp=x;
                      while(temp>0){
                                 d++;
                                 temp/=10;
                      }
                      int []ar=new int[d];
                      int temp1=x;
                      int i=d-1;
                      while(temp1>0){
                                 int a=temp1%10;
                                 ar[i--]=a;
                                 temp1/=10;
                      }
                      for(int j=1;j<ar.length;++j){
                                 if(ar[j]>=5){
                                            ar[j]=9-ar[j];
                                 }
                      }
                                 if(ar[0]!=9)
                                 ar[0]=9-ar[0];
                             for(int ele:ar)
                             System.out.println(ele);
           }
}

import java.util.Scanner;
public class Solution_1 {
    public static void main(String args[])
    {
        Scanner input=new Scanner(System.in);
        long num=input.nextLong(),n=0,a=1;
        //p=num;
        while(num>0)
        {
            if(num%10>=5)
            {
                n=n+((9-(num%10))*a);

            }
            else
            {
                n=n+((num%10)*a);
            }
            a*=10;
            num/=10;
        }
        if(n!=0)
        System.out.println(n);
        else
            System.out.println(9);

    }

}

/**
 * Created by mohammad on 7/25/16.
 */
import java.util.*;

public class Problem514A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String in = s.next();
        int l = in.length();
        int[] digits = new int[l];
        for (int i = 0; i < l; i++) {
            digits[i] = Character.getNumericValue(in.charAt(i));
            if (9 - digits[i] < digits[i]){
                digits[i] = 9 - digits[i];
            }
        }
        for (int i = 0; i <= (l-1); i++){
            System.out.print(digits[i]);
        }
    }
}

import java.awt.geom.AffineTransform;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n =in.nextLong();
        long pow = 1;
        long res=0;
        while(n>0){
            long num = n%10;
            if(num<=4){
                res+=pow*num;
            }
            else{
                res+=pow*(9L-num);
            }
            pow*=10;
            n/=10;
        }
        System.out.println(res);
    }
}

  import java.util.*;
public class NewClass1 {

    public static void main(String [] args)
    {

        Scanner in=new Scanner(System.in);
       String s=in.next();

       for(int i=0;i<s.length();i++)
         {

              String d=""+s.charAt(i);
             int y=Integer.parseInt(d);

       System.out.print((y!=0&&y>4&&y<9)?(9-y):y);

       }

}}

import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class TaskA
{
    Scanner in;
    PrintWriter out;
    long n;
    ArrayList<Long> digits = new ArrayList<Long>();

    public static void main(String[] args)
    {
        TaskA mainTest = new TaskA();

        mainTest.readData();
        mainTest.solve();
        mainTest.outputData();
    }

    public TaskA()
    {
        in = new Scanner(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
    }

    public void readData()
    {
        n = in.nextLong();
    }

    public void solve()
    {
        while (n > 0) {
            long digit =  (n % 10);
            if (digit >= 5) {
                digit = 9 - digit;
            }
            digits.add(digit);

            n /= 10;
        }
    }

    public void outputData()
    {
        long answer = 0;

        for (Long digit : digits) {
            answer = answer * 10 + digit;
        }

        out.println(answer);
        out.flush();
    }
}

import java.io.PrintStream;
import java.util.Scanner;

public class A {

    static Scanner in = new Scanner(System.in);

    static PrintStream out = System.out;

    public static void main(String[] args) {
        StringBuilder x = new StringBuilder(in.next());

        for (int i = 0; i < x.length(); i++){
            int d = x.charAt(i) - '0';

            d = Math.min(d, 9 - d);
            x.setCharAt(i, (char)(d + '0'));
        }

        out.println(x);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);

        String str = in.nextLine();

        String res="";
        char ch;
        for(int i=0 ; i<str.length() ; i++){
            ch = str.charAt(i);
            if( res.length() == 0 && ch == '9' ){
                continue;
            }
            if( ch >= '5' ){
                res += ( 9 - (ch - '0' ) );
            }
            else{
                res += ch;
            }
        }

        if( res.length() != 0 ){
            System.out.println(res);
        }
        else{
            System.out.println("0");
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class ChewbacaAndNumbers {
	public static void main(String[] args)throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = s.length()-1; i >=0; i--) {
			if('9'-s.charAt(i) < s.charAt(i) - '0' )
				if(i==0 && s.charAt(i) == '9')
					continue;
				else
					sb.append('9'-s.charAt(i));
			else
				sb.append(s.charAt(i));
		}
		System.out.println(sb);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}
}

import java.util.Scanner;

/**
 *
 * @author HP
 */
public class CodeForces {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] x = in.next().toCharArray();
        for (int i = 0; i < x.length; i++) {
            if (i == 0 && (x[i] - '0') == 9) {
                System.out.print(9);
            } else {
                int y = 9 - (x[i] - '0');
                int min = Math.min(x[0] - '0', y);
                System.out.print(min);
            }
        }
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EigenFunk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AChewbascaAndNumber solver = new AChewbascaAndNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class AChewbascaAndNumber {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long x = in.readLong();
            String r = "";

            while (x > 0) {
                long d = x % 10;
                r = Math.min(d, 9 - d) + r;
                x = x / 10;
            }
            out.println(r);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

// package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scan = new Scanner(System.in);

        String str = scan.nextLine();
        char [] s = new char[str.length()];
        for(int i = 0; i < str.length(); i++) {
            s[i] = str.charAt(i);
        }

        if(s[0] >= '5' && s[0] != '9') {
            s[0]  = (char)('9' - s[0]);
        }

        for(int i = 1; i < str.length(); i++) {
            if(s[i] >= '5') {
                s[i] = (char) ('9' -s[i] + 48);
            }
        }

        System.out.println(s);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws Exception {
		final FastScanner scanner = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
		String n = scanner.nextToken();

		String res = "";

		res = getInvertedDigit(n);

		int i;
		for(i = 0; i < res.length(); ){
			if(res.charAt(i) == '0'){
				i++;
			}
			else{
				break;
			}
		}
		final String substring = res.substring(i);
		if(substring.isEmpty()) {
			System.out.println(n.charAt(0)+getInvertedDigit(n.substring(1)));
		}
		else{
			System.out.println(substring);
		}
	}

	private static String getInvertedDigit(String n) {
		String res = "";
		for(int i = 0 ; i < n.length(); i++){
			final int digit = n.charAt(i) - '0';
			final int invertedDigit = 9 - digit;

			res += digit < invertedDigit ? digit : invertedDigit;
		}
		return res;
	}

}

class FastScanner {

    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }

	int[] nextIntArray(int n) throws Exception {
		int[] array = new int[n];
		for (int i = 0; i < n; i++)
			array[i] = nextInt();
		return array;
	}

	long[] nextLongArray(int n) throws Exception {
		long[] array = new long[n];
		for (int i = 0; i < n; i++)
			array[i] = nextLong();
		return array;
	}
}

import java.util.*;

public class Main {

    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
        char[] arr = scan.next().toCharArray();
        Integer[] nums = new Integer[arr.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(Character.toString(arr[i]));
        }
        int min = Collections.min(Arrays.asList(nums));
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != min) {
                nums[i] = 9 - nums[i];
            }
        }
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i]);
        }
    }
}

import java.util.Scanner;

public class ChewNumber {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        long max = 0;
        long number = scanner.nextLong();
        String result = number + "";

        while (number > 0) {
            long digit = number % 10;
            max = Math.max(digit, max);
            number /= 10;
        }
        System.out.println(result.replace((char) (max + 48), (char) (9 - max + 48)));
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EigenFunk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AChewbascaAndNumber solver = new AChewbascaAndNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class AChewbascaAndNumber {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long x = in.readLong();
            String r = "";

            while (x > 0) {
                long d = x % 10;
                r = Math.min(d, 9 - d) + r;
                x = x / 10;
            }
            long resp = Long.parseLong(r);
            out.println(resp == 0 ? 9 : resp);
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

import java.util.*;
public class A {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String s = in.next();
		String ans = "";
		for(int i = 0; i < s.length(); i ++){
			ans+= Math.min(9 - (s.charAt(i) - '0'), s.charAt(i) - '0');
		}
		long p = Long.parseLong(ans);
		if(p == 0) p = 9;
		System.out.println(p);
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();

		String line = in.next();
		char[] l = line.trim().toCharArray();
		int a = Integer.parseInt(""+l[0]);
		list.add(a);

		for(int i =1;i<l.length;i++){

			if((""+l[i]).equals(""+a)){
				list.add(Integer.parseInt(""+l[i]));
			}
			else {
				int b = 9- Integer.parseInt(""+l[i]);
				list.add(b);
			}
		}
		for(int i =0;i<list.size();i++){
			System.out.print(list.get(i));
		}
		System.out.println();
	}
}

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
     	Scanner sc = new Scanner(System.in);
     	String s = sc.next();
     	StringBuilder sb = new StringBuilder("");
     	int  n1= s.length();
     	if(s.equals("9")){
     	System.out.println(s); return;}

     	for(int i=0;i<n1;i++){
     		int n = (int)s.charAt(i)-48;
     		if(n>4){
     			n = 9 -n;
     		}
     		sb.append(n+"");
     	}
     	while(sb.length()>1 && sb.charAt(0)=='0')
     		sb.deleteCharAt(0);

     	System.out.println(sb);

    }
}

import java.util.Scanner;

/**
 ** Created by Alik on 11/8/2015.
 */
public class Problem_514A {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String number = in.nextLine();
        int result = 0;

        int temp;
        for (int i = 0; i < number.length(); i++){
            temp = number.charAt(i)-48;
            if (temp > 4 && temp != 9)
                temp = 9-temp;
            result = result*10 + temp;
        }
        System.out.print(result);
    }
}