import Control.Applicative
import Data.List

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

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

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

conv :: Char -> Int
conv c = case c of
  '#' -> 1
  _   -> 0

solve :: [[Int]] -> Int
solve (xs:xss) = iter [] xs xss
  where
    phi (l,u:us) x = ((m,us), m)
      where
        m = min l u + x
    iter [] ys (zs:zss) = iter (scanl1 (+) ys) zs zss
    iter xs ys []       = fst $ fst $ mapAccumL phi (maxBound, xs) ys
    iter xs ys (zs:zss) = iter ws zs zss
      where
        ws = snd $ mapAccumL phi (maxBound, xs) ys

-- I/O

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