object Main extends App {
  val Array(h, w) = io.StdIn.readLine().split(' ').map(_.toInt)
  val field = Array.fill(h)(io.StdIn.readLine().toCharArray)
  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
  val d = Array((1,0),(-1,0),(0,1),(0,-1))
  while(!queue.isEmpty) {
    val ((x, y), count) = queue.poll()
    for {
      i <- d.indices
      nx = x + d(i)._1
      ny = y + d(i)._2
      if nx >= 0 && nx < w && ny >= 0 && ny < h
      if field(ny)(nx) == '.'
    } {
      field(ny)(nx) = '#'
      queue.offer(((nx, ny), count+1))
    }
    if (times < count) times = count
  }
  println(times)
}