{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Data.Array.IO
import Data.IORef
import qualified Data.Map as M
import Control.Monad
import qualified Data.ByteString.Char8 as BC

main :: IO ()
main = do
  [iy,ix] <- map read . words <$> getLine :: IO [Int]
  routeArr <- newArray_ ( (0,0), (iy-1,ix-1) ) :: IO (IOUArray (Int,Int) Bool)
  forM_ [0..(iy-1)] $ \ny -> do
    routesList <- BC.getLine
    forM_ [0..(ix-1)] $ \nx -> do
      case routesList `BC.index` nx of
        '.' -> writeArray routeArr (ny,nx) True -- '.'
        '#' -> writeArray routeArr (ny,nx) False -- '#'
        _ -> return ()
  times <- solve (iy-1,ix-1) routeArr
  print times

solve :: (Int,Int) -> IOUArray (Int,Int) Bool -> IO Int
solve (y,x) ioArr = do
  memo <- newIORef (M.empty)
  firstB <- readArray ioArr (0,0)
  if firstB then
    do modifyIORef memo (M.insert (0,0) 0)
    else
      modifyIORef memo (M.insert (0,0) 1)
  initial (y,x) ioArr memo
  m <- readIORef memo
  -- print m
  let v = fromJust $ M.lookup (y,x) m
  lastB <- readArray ioArr (y,x)
  if lastB
    then return v
    else return $ v+1
  where
    initial :: (Int,Int) -> IOUArray (Int,Int) Bool -> IORef (M.Map (Int,Int) Int) -> IO ()
    initial (y,x) ioArr memo = do
      forM_ [1..y] $ \i -> do
        m <- readIORef memo
        upB <- readArray ioArr (i-1,0)
        myB <- readArray ioArr (i,0)
        let val = fromJust $ M.lookup (i-1,0) m
            v = if (not myB) || upB
                then val
                else val+1
        modifyIORef memo (M.insert (i,0) v)
      forM_ [1..x] $ \j -> do
        m <- readIORef memo
        leB <- readArray ioArr (0,j-1)
        myB <- readArray ioArr (0,j)
        let val = fromJust $ M.lookup (0,j-1) m
            v = if (not myB) || leB
                then val
                else val+1
        modifyIORef memo (M.insert (0,j) v)
      forM_ [1..y] $ \yy -> do
        forM [1..x] $ \xx -> do
          m <- readIORef memo
          upB <- readArray ioArr (yy-1,xx)
          leB <- readArray ioArr (yy,xx-1)
          myB <- readArray ioArr (yy,xx)
          let upNowVal = fromJust $ M.lookup (yy-1,xx) m
              upNextVal = if (not myB) || upB
                          then upNowVal
                          else upNowVal+1
              leftNowVal = fromJust $ M.lookup (yy,xx-1) m
              leftNextVal = if (not myB) || upB
                            then leftNowVal
                            else leftNowVal+1
          modifyIORef memo $ M.insert (yy,xx) (min upNextVal leftNextVal)
