object Main extends App {
  val stdin = new MyStdIn
  val Array(h, w) = stdin.readLine().filter(_ != ' ').map(_ - '0')
  val field = Array.fill(h)(stdin.readLine())
  val queue = new java.util.ArrayDeque[((Int, Int), Int)]()
  for (j <- 0 until h; i <- 0 until w; if field(j)(i) == '#') queue.offer(((i, j), 0))
  var times = 0
  while(!queue.isEmpty) {
    val ((x, y), count) = queue.poll()
    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) == '.'
    } {
      field(p._2)(p._1) = '#'
      queue.offer((p, count+1))
    }
    if (times < count) times = count
  }
  println(times)
}

class MyStdIn {
  val in: java.io.InputStream = System.in
  var head = 0
  var last = 0
  val bufSize = 1024
  val buf = new Array[Byte](bufSize)
  private def empty: Boolean = head >= last
  private def read(): Unit = {
    val len = in.read(buf)
    head = 0
    last = len - 1
  }
  def readLine(): Array[Byte] = {
    if (empty) read()
    val ret = collection.mutable.ArrayBuffer.empty[Byte]
    while (buf(head) != '\n' && head <= last) {
      ret += buf(head)
      if (head + 1 >= bufSize) read()
      else head += 1
    }
    head += 1
    ret.toArray
  }
}