import Control.Monad
import Data.Maybe (mapMaybe)
import Data.Array.Unboxed ((!), UArray)
import qualified Data.Array.Unboxed as U
import qualified Data.Array.ST as ST

main = do
    [h, w] <- map (read :: String -> Int) . words <$> getLine
    a <- concat <$> replicateM h getContents
    let ls = U.listArray ((1, 1), (w, h)) a :: UArray (Int, Int) Char
    let answer = maximum . map (minRange ls) $ U.indices ls
    print answer
    where getRange :: UArray (Int, Int) Char -> (Int, Int) -> (Int, Int) -> Maybe Int
          getRange l (ex, ey) (x, y) = if   (l ! (x, y)) == '#'
                           then Just $ abs (ex - x) + abs (ey -y)
                           else Nothing
          minRange l ec = minimum . mapMaybe (getRange l ec) $ U.indices l
