require 'set'
H, W = gets.split(" ").map(&:to_i)
D = [[-1, 0], [+1, 0], [0, -1], [0, +1]]

map = []
H.times do
  map << gets.chomp.split(//)
end

b = Set.new
cntw = 0
H.times do |h|
  W.times do |w|
    if map[h][w] == "."
      cntw += 1
    else
      b << [w, h]
    end
  end
end

turn = 0
while cntw > 0
  turn += 1
  b2 = Set.new
  b.each do |(w, h)|
    D.each do |(dx, dy)|
      x = w + dx
      y = h + dy
      if (0 <= y && y < map.size) && (0 <= x && x < map[y].size) && map[y][x] == '.'
        map[y][x] = '#'
        cntw -= 1
        b2 << [x, y]
      end
    end
  end
  b = b2
end

puts turn
