import java.util.*
import java.math.*
import java.lang.Math.*


private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }
//private val MOD = 1e9.toLong()+7
//private val INF = Int.MAX_VALUE/2
//private val LINF = Long.MAX_VALUE/2


class GridBfs(val G: List<String>, val Start:Char = '#',
              val ToPaint:Char = '.') {
    var H:Int = 0
    var W:Int = 0
    data class Pos(val x: Int, val y: Int)
    private val starts = ArrayList<Pos>()
    init {
        H = G.size
        W = G[0].length
        G.forEachIndexed{i, row ->
            row.forEachIndexed{j, cell ->
                if (cell == Start) starts.add(Pos(i,j))
            }
        }
    }
    private val dx = intArrayOf(0,1,0,-1)
    private val dy = intArrayOf(1,0,-1,-0)
    private val INF = Int.MAX_VALUE/2
    fun fill(): Int {
        val que = LinkedList<Pos>()
        val step = Array(H){IntArray(W){INF} }
        for (ps in starts) {
            que.addLast(ps)
            step[ps.x][ps.y] = 0
        }
        while (que.isNotEmpty()) {
            val (x, y) = que.removeFirst()
            for (i in dx.indices) {
                val nx = x + dx[i]; val ny = y + dy[i]
                if (nx<0 || H<=nx || ny<0 || W<=ny) {
                    continue
                }
                if (step[nx][ny] > step[x][y] + 1) {
                    step[nx][ny] = step[x][y] + 1
                    que.addLast(Pos(nx, ny))
                }
            }
        }

        var res = -INF
        step.forEach { it.forEach { res = max(res, it) } }
        return res
    }
}


fun solveA(A: Array<String>): Int {
    val bfs = GridBfs(A.toList())
    return bfs.fill()
}


fun main(args: Array<String>) {
    val (H, W) = readListInt()
    val A = Array<String>(H){""}
    for (i in 0 until H) {
        A[i] = readString()
    }

    val ans = solveA(A)

    println(ans)
}
