'use strict'

const main = input => {
	const args = input.split('\n')
	const n = parseInt(args[0].split(' ')[0], 10)
	const p = args[1].split(' ').map(Number)
	let cnt = 0

	for (let i = 1; i < (n - 1); i++) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1]) cnt ++
		else if (p[i - 1] > p[i] && p[i] > p[i + 1]) cnt ++
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
