{-# LANGUAGE OverloadedStrings #-}
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)
  color <- readArray ioArr (y,x)
  if color then
    loop 0 color (y,x) ioArr memo
    else
    loop 1 color (y,x) ioArr memo
  where
    loop :: Int -> Bool -> (Int,Int) -> IOUArray (Int,Int) Bool -> IORef (M.Map (Int,Int) Int) -> IO Int
    loop n color (iy,ix) _ memo = do
      m <- readIORef memo
      c <- readArray ioArr (iy,ix)
      let next = if (not color || c)
                 then n
                 else n+1
      case (iy,ix) of
        (0,0) -> do
          return next
        (0,jx) -> do
          case M.lookup (0,jx-1) m of
            Just v -> return v
            Nothing -> do
              v <- loop next c (0,jx-1) ioArr memo
              modifyIORef memo (M.insert (0,jx-1) v)
              return v
        (jy,0) -> do
          case M.lookup (jy-1,0) m of
            Just v -> return v
            Nothing -> do
              v <- loop next c (jy-1,0) ioArr memo
              modifyIORef memo (M.insert (jy-1,0) v)
              return v
        (jy,jx) -> do
          up <- case M.lookup (jy-1,jx) m of
                  Just v -> return v
                  Nothing -> loop next c (jy-1,jx) ioArr memo
          left <- case M.lookup (jy,jx-1) m of
                  Just v -> return v
                  Nothing -> loop next c (jy,jx-1) ioArr memo
          let v = min up left
          modifyIORef memo (M.insert (jy,jx) v)
          return v
