import scala.io.{StdIn => in}

object Main extends App {
  val Array(h, w) = in.readLine.split(" ").map(_.toInt)
  val n = h * w

  val arr = Iterator.continually(in.readLine)
    .take(h)
    .map(_.map(ch => if(ch == '#') 1 else 0).toArray)
    .toArray
  
  val dy = Array( 1, 0,-1, 0)
  val dx = Array( 0, 1, 0,-1)
  var cnt = 0
  var size = arr.map(e => e.count(_ == 1)).sum
  var t = 1
  while(size < n) {

    for {
      i <- 0 until h
      j <- 0 until w
      if arr(i)(j) == t
    } {
        val p = i*w+j
      for(k <- 0 until 4) {
        val y = i + dy(k)
        val x = j + dx(k)
        if(0 <= y && y < h && 0 <= x && x < w && arr(y)(x) == 0) {
          arr(y)(x) = t + 1
          size += 1
        }
      }
    }
    t += 1
    cnt += 1
    // println(size)
  }

  println(cnt)
}