program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,nd,cnt
    integer(int32), allocatable:: a(:),da(:)

    read*, n
    allocate(a(n),da(n-1))
    read*, a(:)

    do i=1,n-1
        da(i) = a(i+1)-a(i)
    end do
    deallocate(a)
    cnt=1
    nd = da(1)
    do i=2,size(da)
        if (da(i)==0 .or. nd==0 .or. (da(i) >0 .eqv. nd>0)) then
            if (nd==0) nd=da(i)
        else
            cnt=cnt+1
            if (i+1 <= size(da)) nd=da(i+1)
        end if
    end do
    print'(i0)', cnt
end program name