main=do
    line<-getLine
    line<-getLine
    let p = [read x::Int|x<-words line]
    print $ solve p

solve ::[Int]->Int
solve [] =0
solve (y:[])=0
solve (y:z:[])=0
solve (x:y:z:s)=if (x<y && y<z) || (z<y && y<x) then (1+(solve (y:z:s))) else solve (y:z:s)
