S=gets.strip
T=gets.strip
dp=Array.new(S.size) { Array.new(T.size,"") }
for i in 0...S.size
  dp[i][0]=S[0,i+1].include?(T[0]) ? T[0] : ""
end

for i in 0...T.size
  dp[0][i]=S[0,i+1].include?(S[0]) ? S[0] : ""
end
# $stderr.print dp

for i in 1...S.size
  for j in 1...T.size
    dp[i][j]=dp[i-1][j-1] + S[i] if S[i]==T[j]
    dp[i][j]=dp[i-1][j].size <= dp[i][j-1].size ? dp[i][j-1] : dp[i-1][j] if S[i]!=T[j]
  end
end
puts dp[S.size-1][T.size-1]
