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

remain = []
search_range =[]

for i in 0..H-1 do
  for j in 0..W-1 do
    remain << [i,j]
  end
end


H.times do |i|
  grid = gets.chomp
  for j in 0..W-1 do
    if grid[j] == "#"
      search_range << [i,j]
      remain.delete([i,j])
    end
  end
end

dxy = [
  [0,1],
  [0,-1],
  [1,0],
  [-1,0]
]
max = 0

while !remain.empty? do
  tmp = []
  flg = false
  search_range.each do |x,y|
    dxy.each do |dx, dy|
      if remain.include?([x+dx, y+dy])
        tmp << [x+dx, y+dy]
        remain.delete([x+dx,y+dy])
        flg = true
      end
    end
  end
  max += 1 if flg
  search_range = tmp
end

puts max
