def LCS(str1,str2):
res = [[0]*len(str2) for _ in range(len(str1))]
max_len=0
max_str=[]
for i in range(len(str1)):
for j in range(len(str2)):
if str1[i]==str2[j]:
if i>0 and j>0:
res[i][j]=1+res[i-1][j-1]
else:
res[i][j]=1
if res[i][j]>max_len:
max_len=res[i][j]
max_str=[str1[i-max_len+1:i+1]]
elif res[i][j]==max_len:
max_str.append(str1[i-max_len:i])
return max_str
str1,str2=(input().split())
n=LCS(str1,str2)