import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str1 = sc.nextLine();//短串
            String str2 = sc.nextLine();//长串
            if(str1.length()>str2.length()){
                String temp=str1;
                str1=str2;
                str2=temp;
            }
            char[] chars1 = str1.toCharArray();
            char[] chars2 = str2.toCharArray();
           
            int[][] dp = new int[chars1.length + 1][chars2.length + 1];
            int max = 0;
            for (int i = 1; i <= chars1.length; i++) {
                for (int j = 1; j <= chars2.length; j++) {
                    if (chars1[i - 1] != chars2[j - 1]) continue;
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    max = Math.max(dp[i][j], max);
                }
            }
            int signal=0;
            for (int i = 1; i <= chars1.length; i++) {                
                for (int j = 1; j <= chars2.length; j++) {
                    if(max == dp[i][j] && signal==0){
                        signal=1;
                        System.out.println(str1.substring(i-max,i));
                    } 
                }
            }
        }
    }
}