import java.util.ArrayDeque

fun main(args: Array<String>) {
    val INF = 1000000000
    val (H, W) = readInputLine().split(" ").map { it.toInt() }
    
    val map = Array(H) { readInputLine().toCharArray() }
    val dist = Array(H) { IntArray(W) { 1000000000 } }
    var maxDist = 0
    
    val queue = ArrayDeque<Pair<Int, Int>>()
    
    for (i in 0 until H) {
        for (j in 0 until W) {
            if (map[i][j] == '#') {
                dist[i][j] = 0
                queue.add(Pair(i, j))
            }
        }
    }

    while (!queue.isEmpty()) {
        val (y, x) = queue.poll()!!
        
        val nowDist = dist[y][x]
        
        if (nowDist > maxDist) {
            maxDist = nowDist
        }
        
        for (i in -1..1) {
            if (y + i < 0 || y + i >= H) {
                continue
            }
            for (j in -1..1) {
                if (x + j < 0 || x + j >= W) {
                    continue
                }
                if ((i == 0 && j == 0) || (i * j != 0)) {
                    continue
                }
                
                if (nowDist + 1 < dist[y + i][x + j]) {
                    dist[y + i][x + j] = maxDist + 1
                    queue.add(Pair(y + i, x + j))
                }
            }
        }
    }
    
    println(maxDist)
}

fun readInputLine(): String {
    return readLine()!!
}
