def myfunc(x):
    for j in range(len(a)-x+1):
        if a[j:j+x] in b:
            return(a[j:j+x])
    return None

while True:
    try:
        a = input() #short
        b = input() #long
        if len(a) > len(b):
            a, b = b, a
        for i in range(len(a),0,-1):
            result = myfunc(i)
            if result != None:
                break
        print(result)
    except:
        break