s=gets.chomp.split("")
t=gets.chomp.split("")
d=Array.new(s.size+1){Array.new(t.size+1,0)}
1.upto(s.size){|i| 1.upto(t.size){|j|
  if s[i-1]==t[j-1]
    d[i][j]=d[i-1][j-1]+1 if d[i][j]<d[i-1][j-1]+1
  end
  d[i][j]=d[i][j-1] if d[i][j]<d[i][j-1]
  d[i][j]=d[i-1][j] if d[i][j]<d[i-1][j]
}}
#puts d[s.size][t.size]
i=s.size
j=t.size
res=""
while i>0 and j>0
  case d[i][j]
  when d[i-1][j]
    i-=1
  when d[i][j-1]
    j-=1
  when d[i-1][j-1]+1
    res=s[i-1]+res
    i-=1;j-=1
  end
end
puts res