{-# OPTIONS_GHC -O3 #-}
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [h, w] <- getIntList
  g <- replicateM h getLine
  let g' = V.fromList $ concat g

  let getPos v r c | (r > h || c > w) = '#'
                   | otherwise = v V.! ((r-1)*w + (c-1))
      inf = 30000
      flipPos vm r c = do
        x <- VM.read vm ((r-1)*w + (c-1))
        let x' = if x == '.' then '#' else '.'
        VM.write vm ((r-1)*w + (c-1)) x'

  let dfs r c ct v | (r == h && c == w) = if getPos v r c == '.'
                                          then return ct
                                          else return (ct+1)
                   | (r > h || c > w) = return inf
                   | otherwise = do
                       if getPos v r c == '.'
                         then do ct1 <- dfs r (c+1) ct v
                                 ct2 <- dfs (r+1) c ct v
                                 return $ min ct1 ct2
                         else do (r', c', v') <- maxFlip r c v
                                 dfs r' c' (ct+1) v'

      maxFlip r c v = let (r', c') = dfs2 r c v
                      in
                        do vm <- V.thaw v
                           forM_ [r..r'] $ \i ->
                             forM_ [c..c'] $ \j -> flipPos vm i j
                           v' <- V.freeze vm
                           return (r', c', v')

      dfs2 r c v = let (r1, c1) =
                         if ((r < h) && getPos v (r+1) c == '#')
                         then dfs2 (r+1) c v
                         else (r, c)
                       (r2, c2) =
                         if ((c < w) && getPos v r (c+1) == '#')
                         then dfs2 r (c+1) v
                         else (r, c)

                       d1 = (h+w-r1-c1)
                       d2 = (h+w-r2-r2)
                   in
                     if d1 < d2 then (r1, c1) else (r2, c2)

  ans <- dfs 1 1 0 g'
  print ans