local s=io.read()
local t=io.read()
local n=#s
local m=#t

local dp={}
for i=1,n+1 do
    dp[i]={}
    for j=1,m+1 do
        dp[i][j]=0
    end
end

for i=1,n do
    for j=1,m do
        if s:byte(i)==t:byte(j) then
            dp[i+1][j+1]=math.max(dp[i][j]+1,dp[i+1][j],dp[i][j+1])
        else
            dp[i+1][j+1]=math.max(dp[i+1][j],dp[i][j+1])
        end
    end
end

local answer=""
while n>0 and m>0 do
    if dp[n+1][m+1]==dp[n][m+1] then
        n=n-1
    elseif dp[n+1][m+1]==dp[n+1][m] then
        m=m-1
    else
        answer=s:sub(n,n)..answer
        n=n-1
        m=m-1
    end
end
print(answer)