s = gets
t = gets

d = Array.new(s.length + 1){ Array.new(t.length + 1){ 0 }}

(1..(s.length)).each do |i|
  (1..(t.length)).each do |j|
    d[i][j] = s[i-1] == t[j-1] ? d[i-1][j-1] + 1 : [d[i-1][j], d[i][j-1]].max
  end
end
puts d[-1][-1]