'use strict'
function Main(input) {
    input = input.split("\n").map(line => {
      return line.split('')
    })
    input.shift()

    const distance = (a, b) => {
      return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]) 
     } 

    let sharps = []
    input.forEach((line, i) => {
      line.forEach((elem, j) => {
        if(elem === '#') sharps.push([i, j]) 
      })
    })

    const minDists = input.map((line, i) => {
      let newLine = line.map((elem, j) => {
        let dists = sharps.map(s => distance(s, [i,j]))
        return Math.min(...dists)
      }) 
      return newLine
    })

    const maxNum = (arr) =>  {
      const m = arr.map(line => {
        return Math.max(...line)
      })
      return Math.max(...m) 
   }  

    let maxMin = maxNum(minDists)

    console.log(maxMin)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))