
import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val Array(h, w) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    var A = Array.fill[Boolean](h+2, w+2)(true)

    val whiteList = ArrayBuffer[(Int, Int)]()

    var wc = 0
    (1 to h) foreach { i =>
      scala.io.StdIn.readLine().zipWithIndex.foreach { case (c, j) =>
        A(i)(j+1) = if (c == '.') {
          whiteList += (i -> (j+1))
          wc += 1
          true
        } else false
      }
    }

    var c = 0
    val bf = ArrayBuffer[(Int, Int)]()
    val blacked = ArrayBuffer[Int]()
    while (wc > 0) {
      bf.clear()
      blacked.clear()
      for {
        idx <- whiteList.indices
        (i, j) = whiteList(idx)
        if !A(i)(j-1) || !A(i)(j+1) || !A(i-1)(j) || !A(i+1)(j)
      } {
        wc -= 1
        bf.append(i -> j)
        blacked.append(idx)
      }

      bf foreach { case (i, j) =>
        A(i)(j) = false
      }
      blacked.reverse foreach whiteList.remove
      c += 1
    }
    println(c)
  }

}
