''' 遍历较短的字符串, 从字符串两端开始截取子串, 判断当前子串是不是公共子串, 然后依据子串的长度判断是否是最长公共子串, 每次保留最长的公共子串。 ''' str1 = input() str2 = input() def max_list(s1, s2): s = '' n = len(s2) for i in range(n): for j in range(n): if s1.find(s2[i:n-j]) < 0: continue else: if len(s2[i:n-j]) > len(s): s = s2[i:n-j] return s def repeat_list(s1, s2): if len(s1) > len(s2): s = max_list(s1, s2) else: s = max_list(s2, s1) return s print(repeat_list(str1, str2))