import scala.math._

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 distances1 = new Array[Array[Int]](h).map(_ => new Array[Int](w))
    val distances2 = new Array[Array[Int]](h).map(_ => new Array[Int](w))
    (0 until h).foreach { i =>
      (0 until w).foreach { j =>
        if (tiles(i)(j) == "#") {
          distances1(i)(j) = 0
        } else if (i > 0 && j > 0) {
          distances1(i)(j) = min(distances1(i - 1)(j), distances1(i)(j - 1)) + 1
        } else if (i > 0) {
          distances1(i)(j) = distances1(i - 1)(j) + 1
        } else if (j > 0) {
          distances1(i)(j) = distances1(i)(j - 1) + 1
        } else {
          distances1(i)(j) = 1
        }
      }
    }
    (0 until h).reverse.foreach { i =>
      (0 until w).reverse.foreach { j =>
        if (tiles(i)(j) == "#") {
          distances2(i)(j) = 0
        } else if (i < h - 1 && j < w - 1) {
          distances2(i)(j) = min(distances1(i + 1)(j), distances1(i)(j + 1)) + 1
        } else if (i < h - 1) {
          distances2(i)(j) = distances1(i + 1)(j) + 1
        } else if (j < w - 1) {
          distances2(i)(j) = distances1(i)(j + 1) + 1
        } else {
          distances2(i)(j) = 1
        }
      }
    }

    val distances = new Array[Array[Int]](h).map(_ => new Array[Int](w))
    (0 until h).foreach { i =>
      (0 until w).foreach { j =>
        distances(i)(j) = min(distances1(i)(j), distances2(i)(j))
      }
    }

    val result = distances.map(_.max).max.toString
    result
  }

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