import java.util.*

class Position(val x: Int, val y: Int, val times: Int)
val delta = arrayOf(
        Pair(1, 0),
        Pair(-1, 0),
        Pair(0, 1),
        Pair(0, -1)
)

fun main(args : Array<String>) {
    val (H, W) = readLine()!!.split(" ").map { it.toInt() }
    val map = Array(H, { Array(W, { false })})

    val queue: Queue<Position> = ArrayDeque()
    (0..(H-1)).forEach { h ->
        readLine()!!.forEachIndexed { w, c ->
            if (c == '#') {
                map[h][w] = true
                queue.offer(Position(h, w, 0))
            } else {
            }
        }
    }
    var times = 0
    while (queue.isNotEmpty()) {
        val position = queue.poll()
        times = position.times
        delta.forEach { d ->
            val dx = d.first
            val dy = d.second
            val x = position.x + dx
            val y = position.y + dy
            val isValid = 0 <= x && x < H && 0 <= y && y < W
            if (isValid && !map[x][y]) {
                map[x][y] = true
                queue.offer(Position(x, y, position.times + 1))
            }
        }
    }

    println(times)
}