H, W = gets.chomp.split(' ').map(&:to_i)
map = []
blacks = []
H.times do |h|
  map.push(gets.chomp.split('').map.with_index do |c, w|
    if c == '#'
      blacks.push [h,w]
    end
    c == '#'
  end)
end
result = 0
next_blacks = []
(H+W).times do
  blacks.each do |h,w|
    [[0,1],[0,-1],[1,0],[-1,0]].each do |dh,dw|
      next if h+dh < 0 || h+dh >= H || w+dw < 0 || w+dw >= W
      next if map[h+dh][w+dw]
      map[h+dh][w+dw] = true
      next_blacks.push [h+dh, w+dw]
    end
  end
  break if next_blacks.size == 0
  blacks = next_blacks
  next_blacks = []
  result += 1
end
puts result