import Control.Applicative
import Data.List

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

loop :: Int -> IO [String]
loop 0 = return []

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

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

solve :: [String] -> Int
solve (xs:xss) = iter [] xs xss
  where
    iter [] ys (zs:zss) = iter (tail $ scanl' phi (0,'.') ys) zs zss
    iter xs ys []       = fst $ fst $ fst $ mapAccumL psi ((maxBound, '#'), xs) ys
    iter xs ys (zs:zss) = iter (snd $ mapAccumL psi ((maxBound, '#'), xs) ys) zs zss
    
    phi (m,'.') '#' = (succ m, '#')
    phi (m,_)   c   = (m, c)

    psi ((k,c),(m,d):ys) '.' = ((ne, ys), ne) where ne = (min k m, '.')
    psi ((k,c),(m,d):ys) '#' = case [c,d] of
      ".." -> ((ne, ys), ne) where ne = (min (succ k) (succ m), '#')
      ".#" -> ((ne, ys), ne) where ne = (min (succ k) m, '#')
      "#." -> ((ne, ys), ne) where ne = (min k (succ m), '#')
      "##" -> ((ne, ys), ne) where ne = (min k m, '#')

-- I/O

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