#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>


using namespace std;


void security()
{
  string s;
  cin >> s;

  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i - 1] == s[i])
    {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}


void fifty_fify()
{
  string s;
  cin >> s;

  sort(s.begin(), s.end());

  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes\n";
  else cout << "No\n";
}


void dodecagon()
{
  int r;
  cin >> r;

  cout << 3 * r * r << "\n";
}


void harmony()
{
  int a, b;
  cin >> a >> b;

  if (a % 2 == b % 2) cout << (a + b) / 2 << "\n";
  else cout << "IMPOSSIBLE\n";
}


void transfer()
{
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c - (a - b)) << "\n";
}


void A_137()
{
  int a, b;
  cin >> a >> b;

  cout << max(a + b, max(a - b, a * b)) << "\n";
}


void red_or_not()
{
  int a;
  cin >> a;
  string s;
  cin >> s;

  if (a >= 3200) cout << s << "\n";
  else cout << "red\n";
}


void tenki()
{
  string s, t;
  cin >> s >> t;

  int cnt = 0;
  for (int i = 0; i < 3; ++i)
  {
    if (s[i] == t[i]) ++cnt;
  }
  cout << cnt << "\n";
}


void password()
{
  int n;
  cin >> n;

  cout << pow(n, 3) << "\n";
}



void ordinary_number()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];

  int cnt = 0;
  for (int i = 1; i < n - 1; ++i)
  {
    if (p[i] != min(min(p[i - 1], p[i]), p[i + 1])
      && p[i] != max(max(p[i - 1], p[i]), p[i + 1])) ++cnt;
  }
  cout << cnt << "\n";
}


void good_distance()
{
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; ++i) for (int j = 0; j < d; ++j) cin >> x[i][j];

  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      float dis = 0;
      for (int k = 0; k < d; ++k)
      {
        dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }

      //整数判定
      for (int m = 0; m <= dis; ++m)
      {
        if (m * m == dis) ++cnt;
      }
    }
  }
  cout << cnt << "\n";
}



void golden_apple()
{
  int n, d;
  cin >> n >> d;

  int cnt = 0;
  while ((2 * d + 1) * cnt < n) ++cnt;

  cout << cnt << "\n";
}


void swap_0or1()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    int p;
    cin >> p;
    if (p != i) ++cnt;
  }

  if (cnt <= 2) cout << "YES\n";
  else cout << "NO\n";
}


void uneven_numbers()
{
  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; ++i)
  {
    string s = to_string(i);
    if (s.size() % 2 == 1) ++ans;
  }
  cout << ans << "\n";
}


void one_clue()
{
  int k, x;
  cin >> k >> x;

  for (int i = x - k + 1; i < x + k; ++i)
  {
    if (i == x + k - 1) cout << i << "\n";
    else cout << i << " ";
  }
}



void resistors_in_parallel()
{
  int n;
  cin >> n;
  vector<float> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  float ans = 0.0;
  for (int i = 0; i < n; ++i) ans += 1.0 / a[i];
  cout << 1.0 / ans << "\n";
}


void power_socket()
{
  int a, b;
  cin >> a >> b;

  if (b == 1) cout << 0 << "\n";

  int cnt = 1, tap = (a - 1) * cnt + 1;
  while (tap < b)
  {
    ++cnt;
    tap += a - 1;
  }
  
  cout << cnt << "\n";
}


void buffet()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n - 1; ++i) cin >> c[i];

  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    ans += b[a[i] - 1];
    if (i > 0 && a[i - 1] + 1 == a[i]) ans += c[a[i - 1] - 1];
  }
  cout << ans << "\n";
}




int main()
{
  //security();
  //fifty_fify();
  //dodecagon();
  //harmony();
  //transfer();
  //A_137();
  //red_or_not();
  //tenki();
  //password();

  ordinary_number();
  //good_distance();
  //golden_apple();
  //swap_0or1();
  //uneven_numbers();
  //one_clue();
  //resistors_in_parallel();
  //power_socket();
  //buffet();
}

Measured memory_bytes: 256