n = int(eval(input()))

l = list(map(int,input().split()))

cnt =0

for i in range(1,n-1):

    if l[i-1]<l[i]<l[i+1] or l[i-1]>l[i]>l[i+1]:

        cnt+=1

print(cnt)
def solve():

    n = int(eval(input()))

    p = list(map(int,input().split()))

    cnt = 0

    for i in range(1,n-1):

        if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:

            cnt+=1

    print(cnt)

if __name__=='__main__':

    solve()
n = int(eval(input()))
l = list(map(int, input().split()))
cnt = 0
for i in range(1, n - 1):
    if l[i - 1] < l[i] < l[i + 1] or l[i - 1] > l[i] > l[i + 1]:
        cnt += 1
print(cnt)

def solve():
    n = int(eval(input()))
    p = list(map(int, input().split()))
    cnt = 0
    for i in range(1, n - 1):
        if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    solve()

-n = int(eval(input())) -l = list(map(int, input().split())) -cnt = 0 -for i in range(1, n - 1): -    if l[i - 1] < l[i] < l[i + 1] or l[i - 1] > l[i] > l[i + 1]: -        cnt += 1 -print(cnt) +def solve(): +    n = int(eval(input())) +    p = list(map(int, input().split())) +    cnt = 0 +    for i in range(1, n - 1): +        if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]: +            cnt += 1 +    print(cnt) + + +if __name__ == "__main__": +    solve()