N = gets.to_i A = gets.split.map &:to_i ans = 0 for i in 1..N-1 if A[i-1] != A[i] && A[i] != A[i+1] && A[i+1] != A[i-1] && (A[i] == [A[i-1], A[i], A[i+1]].max || A[i] == [A[i-1], A[i], A[i+1]].min) ans += 1 end end p ans