import java.io.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class Grep {

    public static void main( String[] args ) throws IOException {

	BufferedReader input = new BufferedReader( new InputStreamReader(System.in) );

	Pattern patron = Pattern.compile( args[0] );

	String ligne;
        while ( ( ligne = input.readLine()) != null ) {
            Matcher matcher = patron.matcher( ligne );
	    if ( matcher.find() ) {
		// La ligne contient le patron: on l'imprime.
                System.out.println( ligne );
            }
        }
    }
}
