s = gets.chomp
t = gets.chomp

match = false
dp = []
s.length.times do |i|
  dp[i] = []
  if i == 0
    t.length.times do |j|
      match = s[0] == t[j] if !match
      if !match
        dp[0][j] = 0
      else
        dp[0][j] = 1
      end
    end
    match = false if s[0] != t[0]
  else
    t.length.times do |j|
      if j == 0
        match = s[i] == t[0] if !match
        if !match
          dp[i][0] = 0
        else
          dp[i][0] = 1
        end
      else
        if s[i] == t[j]
          if dp[i-1][j-1] == dp[i][j-1] && dp[i-1][j-1] == dp[i-1][j]
            dp[i][j] = dp[i][j-1] + 1
          else
            if dp[i][j-1] > dp[i-1][j]
              dp[i][j] = dp[i][j-1]
            else
              dp[i][j] = dp[i-1][j]
            end
          end
        else
          if dp[i][j-1] > dp[i-1][j]
            dp[i][j] = dp[i][j-1]
          else
            dp[i][j] = dp[i-1][j]
          end
        end
      end
    end
  end
end

puts dp[-1][-1]

#s.length.times do |i|
#  p dp[i]
#end
