H, W = gets.split.map(&:to_i)
A = H.times.map { gets.chomp.chars }
visited = Array.new(H) { Array.new(W, Float::INFINITY) }

queue = []

H.times do |y|
  W.times do |x|
    next if A[y][x] == '.'

    queue << [y, x, 0]
  end
end

ans = 0

DY = [-1, 0, 1, 0]
DX = [0, 1, 0, -1]

until queue.empty?
  y, x, d = queue.shift

  next if visited[y][x] <= d
  visited[y][x] = d

  ans = d if ans < d

  DY.zip(DX).each do |dy, dx|
    ny = y + dy
    nx = x + dx
    next if ny < 0 || nx < 0 || H <= ny || W <= nx
    next if A[ny][nx] == '#'

    queue << [ny, nx, d + 1]
  end
end

puts ans
