gets
p = gets.split("\s").map(&:to_i)

former = p.shift
present = p.shift
future = nil
count = 0

while !p.empty?
  future = p.shift
  
  trio = [former, present, future]
  count += 1 if trio.min != present && trio.max != present

  former = present
  present = future
end

p count