import java.util.*

const val INF = 5000000

fun main(args: Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val queue : Queue<Int> = ArrayDeque<Int>()
    val blackLen = Array(h){IntArray(w){ INF }}
    val a = (1..h).map { readLine()!! }
    for(i in a.indices) {
        for(j in a[i].indices) {
            if(a[i][j]=='#') {
                queue.offer(i*w+j)
                blackLen[i][j] = 0
            }
        }
    }
    
    while(!queue.isEmpty()){
        val p = queue.poll()!!
        val i = p/w
        val j = p%w

        if(i>0   && blackLen[i-1][j]==INF) queue.offer((i-1)*w+j)
        if(i<h-1 && blackLen[i+1][j]==INF) queue.offer((i+1)*w+j)
        if(j>0   && blackLen[i][j-1]==INF) queue.offer(i*w+(j-1))
        if(j<w-1 && blackLen[i][j+1]==INF) queue.offer(i*w+(j+1))

        if(i>0)   blackLen[i-1][j] = Math.min( blackLen[i-1][j] , blackLen[i][j]+1 )
        if(i<h-1) blackLen[i+1][j] = Math.min( blackLen[i+1][j] , blackLen[i][j]+1 )
        if(j>0)   blackLen[i][j-1] = Math.min( blackLen[i][j-1] , blackLen[i][j]+1 )
        if(j<w-1) blackLen[i][j+1] = Math.min( blackLen[i][j+1] , blackLen[i][j]+1 )
    }

    val ans = blackLen.map { it.max()!! }.max()!!
    println(ans)

}