H, W = gets.strip.split(" ").map(&:to_i)
HW = Array.new(H) { gets.strip.split("") }

S = Array.new(H) { Array.new(W) }

0.upto(H - 1) do |i|
  0.upto(W - 1) do |j|
    next unless HW[i][j] == "#"
    S[i][j] = 0

    (i - 1).downto(0) do |_i|
      break if HW[_i][j] == "#"
      S[_i][j] = S[_i][j] ? [S[_i][j], (i - _i).abs].min : (i - _i).abs
    end

    (i + 1).upto(H - 1) do |_i|
      break if HW[_i][j] == "#"
      S[_i][j] = S[_i][j] ? [S[_i][j], (i - _i).abs].min : (i - _i).abs
    end

    (j - 1).downto(0) do |_j|
      break if HW[i][_j] == "#"
      S[i][_j] = S[i][_j] ? [S[i][_j], (j - _j).abs].min : (j - _j).abs
    end

    (j + 1).upto(W - 1) do |_j|
      break if HW[i][_j] == "#"
      S[i][_j] = S[i][_j] ? [S[i][_j], (j - _j).abs].min : (j - _j).abs
    end
  end
end

ans = -1

0.upto(H - 1) do |i|
  0.upto(W - 1) do |j|
    a = []

    (i - 1).downto(0) do |_i|
      if S[_i][j]
        a << S[_i][j] + (i - _i).abs
        break
      end
    end

    (i + 1).upto(H - 1) do |_i|
      if S[_i][j]
        a << S[_i][j] + (i - _i).abs
        break
      end
    end

    (j - 1).downto(0) do |_j|
      if S[i][_j]
        a << S[i][_j] + (j - _j).abs
        break
      end
    end

    (j + 1).upto(W - 1) do |_j|
      if S[i][_j]
        a << S[i][_j] + (j - _j).abs
        break
      end
    end

    ans = [ans, a.min].max
  end
end

puts ans
