
H, W = gets.chomp.split.map(&:to_i)
C = []
que = []
H.times do |i|
  s =  gets.chomp
  C << Array.new(W) do |j|
    if s[j] == '#'
      que << [i, j]
      1
    else
      0
    end
  end
end
ans = 0
while que.size > 0
  nq = []
  ans += 1
  que.each do |x, y|
    if x > 0 && C[x-1][y] == 0
      C[x-1][y] = 1
      nq << [x-1, y]
    end
    if y > 0 && C[x][y-1] == 0
      C[x][y-1] = 1
      nq << [x, y-1]
    end
    if x < H-1 && C[x+1][y] == 0
      C[x+1][y] = 1
      nq << [x+1, y]
    end
    if y < W-1 && C[x][y+1] == 0
      C[x][y+1] = 1
      nq << [x, y+1]
    end
  end
  que = nq.dup
end
puts ans - 1