import Data.List

paintLine :: [Char] -> [Char]
paintLine [] = []
paintLine (c:cs)
 | cs == []   = [c]
 | otherwise  = if c == '#' then c : '#' : paintLine (tail cs)
                else if head cs == '#' then '#' : paintLine cs
            	else c : paintLine cs

allPainted :: [[Char]] -> Bool
allPainted table = not $ elem '.' (concat table)

paintNum :: [[Char]] -> Int
paintNum table
 | allPainted table  = 0
 | otherwise         = 1 + paintNum paint
 where paint1 = map paintLine table
       paint2 = transpose $ map paintLine (transpose table)
       paint  = zipWith (zipWith (\x y -> if x == '#' || y == '#' then '#' else '.')) paint1 paint2

main = do
    getLine
    table <- lines <$> getContents
    print $ paintNum table
    
    
    