program am
integer::H,W
integer,allocatable,dimension(:,:)::maze,DP
character(100)::S
integer::dx(2)=[-1,0],dy(2)=[0,-1]
integer::i,j,k
read*,H,W
allocate(maze(H,W))
maze=0
do i=1,H
    read*,S
    do j=1,W
        if(S(j:j)=="#")maze(i,j)=1
    end do
end do
allocate(DP(H,W))
DP=huge(i)/2
DP(1,1)=maze(1,1)
do i=1,H
    do j=1,W
        do k=1,2
            DP(i,j)=min(DP(i,j),&
            DP(max(1,i+dx(k)),max(1,j+dy(k)))+merge(1,0,maze(max(1,i+dx(k)),max(1,j+dy(k)))==0.and.maze(i,j)==1))
        end do
    end do
end do
print"(I0)",DP(H,W)
end program am