import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toStream
    println(solve(lines))
  }

  def solve(lines: Seq[String]): String = {
    val Array(h, w) = lines.head.split(" ").map(_.toInt)
    val tiles = lines.tail.take(h).map(_.split("").filter(_.length > 0).take(w)).toArray
    debug(h, w, tiles.map(_.toSeq).toSeq)

    val blacks = ArrayBuffer.empty[(Int, Int)]
    (0 until h).foreach { i =>
      (0 until w).foreach { j =>
        if (tiles(i)(j) == "#") {
          blacks.append((i, j))
        }
      }
    }
    val newBlacks = ArrayBuffer.empty[(Int, Int)]
    var blackCount = blacks.length
    var loopCounter = 0
    while (blackCount < h * w) {
      newBlacks.clear()
      blacks.foreach { case (i, j) =>
        if (i > 0 && tiles(i - 1)(j) == ".") {
          tiles(i - 1)(j) = "#"
          newBlacks.append((i - 1, j))
        }
        if (i < h - 1 && tiles(i + 1)(j) == ".") {
          tiles(i + 1)(j) = "#"
          newBlacks.append((i + 1, j))
        }
        if (j > 0 && tiles(i)(j - 1) == ".") {
          tiles(i)(j - 1) = "#"
          newBlacks.append((i, j - 1))
        }
        if (j < w - 1 && tiles(i)(j + 1) == ".") {
          tiles(i)(j + 1) = "#"
          newBlacks.append((i, j + 1))
        }
      }
      loopCounter += 1
      blackCount += newBlacks.length
      blacks.clear()
      blacks.appendAll(newBlacks)
    }

    val result = loopCounter.toString
    result
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null)
      println(x)
  }
}
