$s1 = gets.chomp.split('')
$s2 = gets.chomp.split('')

s1_length = $s1.length

s2_length = $s2.length

$table = Array.new(s1_length + 1).map { Array.new(s2_length + 1, 0) }

def max(a, b)
  a < b ? b : a
end

max_common = -1000

s1_length.times do |i|
  s2_length.times do |j|
    $table[i + 1][j + 1] = if $s1[i] == $s2[j]
                             max_common = max($table[i][j] + 1, max_common)
                             $table[i][j] + 1
                           else
                             0
                          end
  end
  puts $table.inspect
end

puts max(s1_length, s2_length) - max_common

