program abc132b
  implicit none
  integer :: n ! 3<=n<=20
  integer :: i, count, a, b, c
  integer, allocatable :: p(:)

  read(*,*) n
  allocate( p(n) )
  read(*,*) p(:)

  count=0
  do i = 2, n-1
    a = p(i-1)
    b = p(i)
    c = p(i+1)

    if (a==b .and. b==c) then
      cycle
    else if ( a<b .and. b<=c) then
      count = count + 1
    else if ( c<b .and. b<=a) then
      count = count + 1
    else
      cycle
    endif
  enddo

  print *, count


  deallocate(p)
end program abc132b
