h, w = gets.split.map(&:to_i)
grids = []
q = []
h.times do |j|
  line = gets.chomp.chars
  grids << line
  line.each_with_index do |s, i|
    if s == '#'
      q << [j, i]
    end
  end
end

ans = 0
while !q.empty? do
  next_q = []
  q.each do |qq|
    cy, cx = qq
    (0..3).each do |i|
      ny = cy + [-1, 0, 1, 0][i]
      nx = cx + [0, -1, 0, 1][i]
      next if ny < 0 || ny > h-1 || nx < 0 || nx > w-1
      next if grids[ny][nx] == '#'

      grids[ny][nx] = '#'
      next_q << [ny, nx]
    end
  end
  q = next_q
  ans += 1
end
puts ans - 1
