{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Data.List

main :: IO ()
main = do
  { [h, w] <- readLineInputs
  ; zss <- loop h
  ; print $ solve zss
  }

loop :: Int -> IO [[(Char, Int)]]
loop 0 = return []

loop n = do
  { xs  <- map conv <$> getLine
  ; xss <- loop (pred n)
  ; return (xs:xss)
  }

conv :: Char -> (Char, Int)
conv c = (c, case c of {'#' -> 1; _ -> 0})

solve :: [[(Char, Int)]] -> Int
solve (xs:xss) = iter [] xs xss
  where
    phi :: (Char, Int) -> (Char, Int) -> (Char, Int)
    phi ('.',m) ('#',_) = ('#', succ m)
    phi (_,  m) (c,  _) = (c,   m)

    psi :: ((Char, Int), [(Char, Int)]) -> (Char, Int) -> (((Char, Int), [(Char, Int)]), (Char, Int))
    psi ((c,m),(d,n):xs) (e,_) = case e of
      '.' -> ((f,xs),f) where f = (e,min m n)
      '#' -> case c of
        '.' -> case d of
          '.' -> ((f,xs),f) where f = (e, min (succ m) (succ n))
          '#' -> ((f,xs),f) where f = (e, min (succ m) n)
        '#' -> case d of
          '.' -> ((f,xs),f) where f = (e, min (succ m) n)
          '#' -> ((f,xs),f) where f = (e, min m n)
    
    iter :: [(Char, Int)] -> [(Char, Int)] -> [[(Char, Int)]] -> Int
    iter [] ys (zs:zss) = iter (scanl1 phi ys) zs zss
    iter xs ys []       = snd $ fst $ fst $ mapAccumL psi (('#',maxBound), xs) ys
    iter xs ys (zs:zss) = iter (snd $ mapAccumL psi (('#',maxBound), xs) ys) zs zss

-- I/O

readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine

