import scala.collection.immutable.Queue

object Main extends App {
  type Point = (Int, Int)
  val Array(h, w) = io.StdIn.readLine().split(' ').map(_.toInt)
  val field = Array.fill(h)(io.StdIn.readLine().toCharArray)
  val queue = (for (j <- 0 until h; i <- 0 until w) yield (i, j))
    .foldLeft(Queue.empty[(Point, Int)]){
      (acc, p) => if (field(p._2)(p._1) == '#') acc.enqueue((p, 0)) else acc
    }
  def loop(queue: Queue[(Point, Int)], times: Int = 0): Int = {
    if (queue.isEmpty) times
    else {
      val (((x, y), count), remain) = queue.dequeue
      val enqueued = (for {
        p <- Seq((x,y-1), (x,y+1), (x-1,y), (x+1,y))
        if p._1 >= 0 && p._1 < w && p._2 >= 0 && p._2 < h
        if field(p._2)(p._1) == '.'
      } yield {
        field(p._2)(p._1) = '#'
        p
      }).foldLeft(remain)((acc, p) => acc.enqueue((p, count+1)))
      loop(enqueued, count)
    }
  }
  println(loop(queue))
}