import Control.Monad
import qualified Data.Set as S
import Data.List

main = do
    [h,w] <- map read . words <$> getLine
    as <- map fst . filter ((== '#') . snd) . zip [(i,j)| i <- [1..h], j <- [1..w]] . concat <$> replicateM h getLine
    print $ solve h w (-1) S.empty as

solve h w k s as
    | S.size s == (h*w) = k
    | otherwise = solve h w (k+1) s' (next as)
        where s' = foldl' (flip S.insert) s as
              next [] = []
              next ((i,j):xs) = nx ++ next xs
                  where nx = [(x,y) | (x,y) <- [(i-1,j),(i+1,j),(i,j-1),(i,j+1)], 1<=x,x<=h,1<=y,y<=w]
