fun main(args: Array<String>) {
	val (h, w) = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
	val input = Array(h) { (readLine() ?: return).toCharArray().map { if (it == '#') 0 else 10000000 }.toIntArray() }
	for (r in 0 until h) for (c in 0 until w) if (input[r][c] > 0) {
		val v1 = if (r > 0) input[r - 1][c] else 10000000
		val v2 = if (c > 0) input[r][c - 1] else 10000000
		input[r][c] = Math.min(v1, v2) + 1
	}
	for (r in h - 1 downTo 0) for (c in w - 1 downTo 0) if (input[r][c] > 0) {
		val v1 = if (r < h - 1) input[r + 1][c] else 10000000
		val v2 = if (c < w - 1) input[r][c + 1] else 10000000
		input[r][c] = Math.min(input[r][c], (Math.min(v1, v2) + 1))
	}
	var max = 0
	for (r in 0 until h) for (c in 0 until w) max = Math.max(max, input[r][c])
	println(max)
}