H, W = gets.split(" ").map(&:to_i)

data = []
H.times do 
  data.push(gets.strip.split(""))
end 

count = 0
loop do 
  change_element = []
  [*(0..(H - 1))].each do |row|
    [*(0..(W - 1))].each do |column|
      if data[row][column] == '.'
        if row != 0 && data[row - 1][column] == '#' || row != H - 1 && data[row + 1][column] == '#' || column != 0 && data[row][column - 1] == '#' || column != W - 1 && data[row][column + 1] == '#'
          change_element.push([row, column])
        end 
      end 
    end 
  end 
  change_element.each{|element| data[element[0]][element[1]] = "#"}
  count += 1
  break if data.flatten.include?('.') == false
end

puts count 