while True:
    try:
        #获取输入数据
        s1 = input()
        s2 = input()
        #获取短字符串和长字符串
        short,long = (s1,s2) if len(s1)<len(s2) else (s2,s1)
        ans = ''
        for n in range(len(short)):
            for m in range(len(short)):
                if short[n:n+m+1] in long and len(short[n:n+m+1])>len(ans):
                    ans = short[n:n+m+1]
        print(ans)

        
    except:
        break