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

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        String str1;
        String str2;
        while ((str1=reader.readLine())!=null){
            str2=reader.readLine();
            if (str1.length()<str2.length()){
                System.out.println(getMaxSubstr(str1,str2));
            }else{
                System.out.println(getMaxSubstr(str2,str1));
            }
        }
    }
    public static String getMaxSubstr(String str1,String str2){
        char[] arr1=str1.toCharArray();
        char[] arr2=str2.toCharArray();
        int len1=str1.length();
        int len2=str2.length();
        int start=0;
        int maxlen=0;
        int[][] maxSubLen=new int[len1+1][len2+1];
        for (int i = 1; i <= len1; i++) {
            for (int j = 1; j <= len2; j++) {
                if(arr1[i-1]==arr2[j-1]){
                    maxSubLen[i][j]=maxSubLen[i-1][j-1]+1;
                    if(maxlen<maxSubLen[i][j]){
                        maxlen=maxSubLen[i][j];
                        start=i-maxlen;
                    }
                }
            }
        }
        return str1.substring(start,start+maxlen);
    }
}