import Control.Monad
import Data.Array.Unboxed (UArray)
import qualified Data.Array.Unboxed as U

main = do
    [h, w] <- map read . words <$> getLine
    a <- concat . words <$> getContents
    let ls = U.listArray ((1, 1), (w, h)) a :: UArray (Int, Int) Char
    let answer = maximum . map (calcTurn ls) $ U.indices ls
    print answer
    where calcTurn :: UArray (Int, Int) Char -> (Int, Int) -> Int
          calcTurn l ec = minimum . map (\(c, _) -> range c ec) . filter (\(_, s) -> s == '#') $ U.assocs l
          range (x, y) (ex, ey) = abs (ex - x) + abs (ey - y)
