module ch
  implicit none
  type char
     character(100)      :: n
  end type char
  type(char),allocatable :: s(:)
end module ch
program main
  
  use ch, only : s
  implicit none
  
  integer(8)              ::  h, w  
  integer(8)              ::  i, j
  integer(8),allocatable  ::  ss(:,:)

  read(*,*) h, w
  allocate( s(h) )
  allocate( ss(h,w) )
  do i = 1, h
    read(*,*) s(i)%n
  end do
  
  ss = 0
  do i = 1, h
    do j = 1, w
      if( s(i)%n(j:j) == "#" ) then
        ss(i,j) = ss(i,j) + 1
      end if
      
      if( i == 1 .and. j /= 1 ) then
        ss(i,j) = ss(i,j) + ss(i,j-1) 
      end if

      if( i /= 1 .and. j == 1 ) then
        ss(i,j) = ss(i,j) + ss(i-1,j)
      end if

      if( i /= 1 .and. j /= 1 ) then
        if( ss(i,j-1) <= ss(i-1,j) ) then   
          ss(i,j) = ss(i,j) + ss(i,j-1) 
        else
          ss(i,j) = ss(i,j) + ss(i-1,j)
        end if
      end if

    end do
  end do
  
  print*, ss(h,w)

end program main
