import scala.collection.mutable.ArrayBuffer
import scala.math._

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

    val cells = ArrayBuffer.empty[(Int, Int)]

    val distances1 = tiles.map(_.map(x => if (x == "#") 0 else 2))
    val distances2 = tiles.map(_.map(x => if (x == "#") 0 else 2))
    (0 until h).foreach { i =>
      (0 until w).foreach { j =>
        if (tiles(i)(j) != "#") {
          cells.clear()
          if (i > 0) cells.append((i - 1, j))
          if (i < h - 1) cells.append((i + 1, j))
          if (j > 0) cells.append((i, j - 1))
          if (j < w - 1) cells.append((i, j + 1))
          if (cells.length > 0)
            distances1(i)(j) = cells.map { case (_i, _j) => distances1(_i)(_j) }.min + 1
        }
      }
    }
    (0 until h).reverse.foreach { i =>
      (0 until w).reverse.foreach { j =>
        if (tiles(i)(j) != "#") {
          cells.clear()
          if (i > 0) cells.append((i - 1, j))
          if (i < h - 1) cells.append((i + 1, j))
          if (j > 0) cells.append((i, j - 1))
          if (j < w - 1) cells.append((i, j + 1))
          if (cells.length > 0)
            distances2(i)(j) = cells.map { case (_i, _j) => distances2(_i)(_j) }.min + 1
        }
      }
    }

    val distances = new Array[Array[Int]](h).map(_ => new Array[Int](w))
    (0 until h).foreach { i =>
      (0 until w).foreach { j =>
        distances(i)(j) = min(distances1(i)(j), distances2(i)(j))
      }
    }

    val result = distances.map(_.max).max.toString
    result
  }

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