-- わからぬ.

import Data.Array.IO
import Control.Monad

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

solve :: (Int,Int) -> IOArray (Int,Int) Bool -> IO Int
solve (y,x) ioArr = do
  color <- readArray ioArr (y,x)
  if color then
    loop 0 color (y,x) ioArr
    else
    loop 1 color (y,x) ioArr
  where
    loop :: Int -> Bool -> (Int,Int) -> IOArray (Int,Int) Bool -> IO Int
    loop n True (0,0) _ = return n
    loop n False (0,0) _ = return $ n+1
    loop n color (0,x) ioArr = do
      c <- readArray ioArr (0,x)
      if c == color then
        loop n c (0,x-1) ioArr
        else
        if color then
          loop (n+1) c (0,x-1) ioArr
        else
          loop n c (0,x-1) ioArr
         
    loop n color (y,0) _ = do
      c <- readArray ioArr (y,0)
      if c == color then
        loop n c (y-1,0) ioArr
        else
        if color then
          loop (n+1) c (y-1,0) ioArr
        else
          loop n c (y-1,0) ioArr
          
    loop n color (y,x) ioArr = do
      c <- readArray ioArr (y,x)
      if c == color then
        do up   <- loop n c (y-1,x) ioArr
           left <- loop n c (y,x-1) ioArr
           return $ min up left
        else
        if color then
          do up   <- loop (n+1) c (y-1,x) ioArr
             left <- loop (n+1) c (y,x-1) ioArr
             return $ min up left
        else
          do up   <- loop n c (y-1,x) ioArr
             left <- loop n c (y,x-1) ioArr
             return $ min up left
