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



/**
 * Write a description of class problem2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class problem2
{
    // instance variables - replace the example below with your own
    private int x;

    /**
     * Constructor for objects of class problem2
     */
    public static void main() throws IOException
    {String g; int f; int d;
        d = 0;
        f=1;
        File file = new File("DATA2.txt");
        Scanner scanner = new Scanner(file);
        
        File fil = new File ("OUT2.txt");
        FileWriter fw = new FileWriter (fil);
        
        for (int y=0; y < 5; y++) {
            
            g = scanner.nextLine();

            
            //System.out.println(g);
            
            for (int i=9; i>0; i--) {
                 //System.out.println(i);
         
                for (int j=0; j < g.length(); j++) {
                    d = j;
                  
                    if (Integer.parseInt(g.substring(j,j+1)) == i) {
                        //System.out.println(i);
                        fw.write(new Integer(i).toString());
                        fw.write ("\r\n");

                        break;    
                    }
                    
                    
                
                
                }
                        if (Integer.parseInt(g.substring(d,d+1)) == i) {
                    break;
                }
            }
        }
            

        
        
       fw.close(); 
        
        
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public int sampleMethod(int y)
    {
        // put your code here
        return x + y;
    }
}

