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 infinity = h + w

    val distances1 = tiles.map(_.map(x => if (x == "#") 0 else infinity))
    (0 until h).foreach { i =>
      (0 until w).foreach { j =>
        if (distances1(i)(j) == infinity) {
          if (i > 0 && j > 0 && (distances1(i - 1)(j) < infinity || distances1(i)(j - 1) < infinity)) distances1(i)(j) = min(distances1(i - 1)(j), distances1(i)(j - 1)) + 1
          else if (i > 0 && distances1(i - 1)(j) < infinity) distances1(i)(j) = distances1(i - 1)(j) + 1
          else if (j > 0 && distances1(i)(j - 1) < infinity) distances1(i)(j) = distances1(i)(j - 1) + 1
        }
      }
    }
    val distances2 = tiles.map(_.map(x => if (x == "#") 0 else infinity))
    (0 until h).reverse.foreach { i =>
      (0 until w).reverse.foreach { j =>
        if (distances2(i)(j) == infinity) {
          if (i < h - 1 && j < w - 1 && (distances2(i + 1)(j) < infinity || distances2(i)(j + 1) < infinity)) distances2(i)(j) = min(distances2(i + 1)(j), distances2(i)(j + 1)) + 1
          else if (i < h - 1 && distances2(i + 1)(j) < infinity) distances2(i)(j) = distances2(i + 1)(j) + 1
          else if (j < w - 1 && distances2(i)(j + 1) < infinity) distances2(i)(j) = distances2(i)(j + 1) + 1
        }
      }
    }
    val distances3 = tiles.map(_.map(x => if (x == "#") 0 else infinity))
    (0 until h).foreach { i =>
      (0 until w).reverse.foreach { j =>
        if (distances3(i)(j) == infinity) {
          if (i > 0 && j < w - 1 && (distances3(i - 1)(j) < infinity || distances3(i)(j + 1) < infinity)) distances3(i)(j) = min(distances3(i - 1)(j), distances3(i)(j + 1)) + 1
          else if (i > 0 && distances3(i - 1)(j) < infinity) distances3(i)(j) = distances3(i - 1)(j) + 1
          else if (j < w - 1 && distances3(i)(j + 1) < infinity) distances3(i)(j) = distances3(i)(j + 1) + 1
        }
      }
    }
    val distances4 = tiles.map(_.map(x => if (x == "#") 0 else infinity))
    (0 until h).reverse.foreach { i =>
      (0 until w).foreach { j =>
        if (distances4(i)(j) == infinity) {
          if (i < h - 1 && j > 0 && (distances4(i + 1)(j) < infinity || distances4(i)(j - 1) < infinity)) distances4(i)(j) = min(distances4(i + 1)(j), distances4(i)(j - 1)) + 1
          else if (i < h - 1 && distances4(i + 1)(j) < infinity) distances4(i)(j) = distances4(i + 1)(j) + 1
          else if (j > 0 && distances4(i)(j - 1) < infinity) distances4(i)(j) = distances4(i)(j - 1) + 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) = Array(distances1(i)(j), distances2(i)(j), distances3(i)(j), distances4(i)(j)).min
      }
    }

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

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