import sys
while True:
    try:
        s1 = input().strip()
        s2 = input().strip()
        #从短的字符串中获取子串,看是否在长串里
        if len(s1) > len(s2):
            s1, s2 = s2, s1
        s_len = len(s1)
        test_len = s_len
        found = False
        #从最长的算起,如果在长串里就是最长的
        while test_len > 0:
            for i in range(s_len - test_len + 1):
                if s1[i:i + test_len] in s2:
                    print(s1[i:i + test_len])
                    found = True
                    break
            if found:
                break
            test_len -= 1
    except:
#         print(sys.exc_info())
        break