import scala.collection.mutable.ArrayBuffer
import scala.math.abs

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))
    debug(h, w, tiles.map(_.toSeq))

    val whites = ArrayBuffer.empty[(Int, Int)]
    val blacks = ArrayBuffer.empty[(Int, Int)]
    tiles.indices.foreach { i =>
      tiles(i).indices.foreach { j =>
        if (tiles(i)(j) == ".") {
          whites.append((i, j))
        } else {
          blacks.append((i, j))
        }
      }
    }
    debug(whites, blacks)

    val result = whites.map { white =>
      blacks.map(black => abs(black._1 - white._1) + abs(black._2 - white._2)).min
    }.max.toString
    result
  }

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