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)]()
    var next = ArrayBuffer[(Int, Int)]()
    for {
      (i, j) <- whiteList
      if !A(i)(j-1) || !A(i)(j+1) || !A(i-1)(j) || !A(i+1)(j)
    } {
      wc -= 1
      bf.append(i -> j)
      if (A(i)(j-1) && j > 1) next.append(i -> (j-1))
      if (A(i)(j+1) && j < w) next.append(i -> (j+1))
      if (A(i-1)(j) && i > 1) next.append((i-1) -> j)
      if (A(i+1)(j) && i < h) next.append((i+1) -> j)
    }
    bf foreach { case (i, j) =>
      A(i)(j) = false
    }
    c += 2

    val nextD = ArrayBuffer[(Int, Int)]()
    while (wc > 0) {
      bf.clear()
      nextD.clear()
      for {
        (i, j) <- next
        if A(i)(j)
      } {
        wc -= 1
        bf.append(i -> j)
        if (A(i)(j-1) && j > 1) nextD.append(i -> (j-1))
        if (A(i)(j+1) && j < w) nextD.append(i -> (j+1))
        if (A(i-1)(j) && i > 1) nextD.append((i-1) -> j)
        if (A(i+1)(j) && i < h) nextD.append((i+1) -> j)
      }
      bf foreach { case (i, j) =>
        A(i)(j) = false
      }
      next = nextD
      c += 1
    }
    println(c)
  }

}
