import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str1 = scan.nextLine();
        String str2 = scan.nextLine();
        String largest = str1.length() >= str2.length() ? str1 : str2;
        String smallest = str1.length() < str2.length() ? str1 : str2;
        char[] chrs1 = smallest.toCharArray();
        char[] chrs2 = largest.toCharArray();
        int ml = 0;
        String ans = "";
        for (int i = 0; i < chrs1.length; i++) {
            for (int j = 0; j < chrs2.length; j++) {
                if (chrs1[i] == chrs2[j]) {
                    int p = 0;
                    while (i + p < chrs1.length && j + p < chrs2.length && chrs1[i + p] == chrs2[j + p]) {
                        p++;
                    }
                    if (p > ml) {
                        ans = largest.substring(j, j + p);
                        ml = ans.length();
                    }
                }
            }
        }
        System.out.println(ans);
    }
}