program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,m,n,h,w,a,b,c
    integer(8),allocatable :: x(:),y1(:),y2(:)
  
    read(*,*) h,w

    allocate(x(w),y1(w),y2(w))
    
    read(*,*)s
    if(s(1:1) .eq. '#')then
        x(1)=1
    else
        x(1)=0
    end if
    do j=2,w
        if(s(j:j) .ne. s(j-1:j-1))then
            x(j)=x(j-1)+1
        else
            x(j)=x(j-1)
        endif
    end do
    
    t=s

    do i=2,h
        read(*,*)s
        do j=1,w
            if(s(j:j) .ne. t(j:j))then
                y1(j)=x(j)+1
            else
                y1(j)=x(j)
            end if
        end do
        y2(1)=y1(1)
        x(1)=y1(1)
        do j=2,w
            if(s(j:j) .ne. s(j-1:j-1))then
                y2(j)=x(j-1)+1
            else
                y2(j)=x(j-1)
            endif
            x(j)=min(y1(j),y2(j))
        end do
        t=s
        
    enddo
    write(*,*)(x(w)+1)/2

    stop
end program sample
  

