import java.util.Scanner;
/**
* HJ65 查找两个字符串a,b中的最长公共子串-中等
*/
public class HJ065 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String s1 = sc.nextLine();
String s2 = sc.nextLine();
String maxSubStr = getMaxSubStr2(s1, s2);
System.out.println(maxSubStr);
}
sc.close();
}
private static String getMaxSubStr2(String s1, String s2) {
String longStr = s1.length() > s2.length() ? s1 : s2;
String shortStr = s1.length() <= s2.length() ? s1 : s2;
String maxSubStr = "";
for (int i = 0; i < shortStr.length(); i++) {
for (int j = 0; j < i + 1; j++) {
String subStr = shortStr.substring(j, shortStr.length() - i + j);
if (longStr.contains(subStr)) {
return subStr;
}
}
}
return maxSubStr;
}
}