#include <iostream>
using namespace std;
int main()
{
    int n,h[100000],var=0;
    cin>>n;
    for(int j=0;j<n;j++)
    {
        cin>>h[j];
    }
    for(int i=1;i<=n;i++)
    {
        for(int c=1;c<=n;c++)
        {
            if(i+1==c)
            {
                var++;
            }else{
                if((h[c]<h[c-1]&&h[i]<h[c-1])||(h[c]>h[c-1]&&h[i]>h[c-1]))
                {
                    var++;
                }
            }
        }
    }
    cout<<var<<endl;
    return 0;
}