#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

void input() {}
template <class T, class... Ts> void input(T &a, Ts &... as) {
  cin >> a;
  input(as...);
}
template <class V> istream &operator>>(istream &i, vector<V> &a) {
  for (auto &e : a)
    i >> e;
  return i;
}

template <class T> void print(T const &a) { cout << a << endl; }
template <class T, class... Ts> void print(T const &a, Ts const &... as) {
  cout << a << " ";
  print(as...);
}
template <class F, class S>
ostream &operator<<(ostream &o, pair<F, S> const &pair) {
  return o << "(" << pair.first << " : " << pair.second << ")";
}
template <size_t I, size_t N, class... Ts> struct OutTuple;
template <> struct OutTuple<1, 0> {
  ostream &operator()(ostream &o, tuple<> const &t) { return o; }
};
template <size_t N, class... Ts> struct OutTuple<N, N, Ts...> {
  ostream &operator()(ostream &o, tuple<Ts...> const &t) {
    return o << get<N - 1>(t);
  }
};
template <size_t I, size_t N, class... Ts> struct OutTuple {
  ostream &operator()(ostream &o, tuple<Ts...> const &t) {
    return OutTuple<I + 1, N, Ts...>{}(o << get<I - 1>(t) << ",", t);
  }
};
template <class... Ts> ostream &operator<<(ostream &o, tuple<Ts...> const &t) {
  return OutTuple<1, sizeof...(Ts), Ts...>{}(o << "(", t) << ")";
}
template <class C> ostream &outContainer(ostream &o, C const &a) {
  o << "[";
  for (auto i = a.begin(), e = a.end(); i != e; o << ((++i != e) ? "," : ""))
    o << *i;
  return o << "]";
}
template <class V> ostream &operator<<(ostream &o, list<V> const &a) {
  return outContainer(o, a);
}
template <class V> ostream &operator<<(ostream &o, vector<V> const &a) {
  return outContainer(o, a);
}
template <class V> ostream &operator<<(ostream &o, set<V> const &a) {
  return outContainer(o, a);
}
template <class V> ostream &operator<<(ostream &o, unordered_set<V> const &a) {
  return outContainer(o, a);
}
template <class K, class V>
ostream &operator<<(ostream &o, map<K, V> const &a) {
  return outContainer(o, a);
}
template <class K, class V>
ostream &operator<<(ostream &o, unordered_map<K, V> const &a) {
  return outContainer(o, a);
}

template <size_t I, size_t N, class... Ts> struct Hash;
template <> struct Hash<1, 0> {
  size_t operator()(size_t h, tuple<> const &t) { return h; }
};
template <size_t N, class... Ts> struct Hash<N, N, Ts...> {
  size_t operator()(size_t h, tuple<Ts...> const &t) {
    auto e = get<N - 1>(t);
    return h * 31 + hash<decltype(e)>{}(e);
  }
};
template <size_t I, size_t N, class... Ts> struct Hash {
  size_t operator()(size_t h, tuple<Ts...> const &t) {
    auto e = get<I - 1>(t);
    return Hash<I + 1, N, Ts...>{}(h * 31 + hash<decltype(e)>{}(e), t);
  }
};
template <class... Ts> size_t compute_hash(tuple<Ts...> const &t) {
  return Hash<1, sizeof...(Ts), Ts...>{}(17, t);
}
namespace std {
template <class... Ts> struct hash<tuple<Ts...>> {
  size_t operator()(tuple<Ts...> const &t) const { return compute_hash(t); }
};
} // namespace std

using lli = long long int;
lli gcd(lli const p, lli const q) { return q == 0 ? p : gcd(q, p % q); }
lli pow(lli const a, lli const n, lli const m) {
  return (!n) ? 1 : (n & 1) ? (((a % m) * pow(a, n - 1, m)) % m) : [=]() {
    lli b = pow(a, n / 2, m);
    return (b * b) % m;
  }();
}
lli inv(lli const a, lli const p) { return pow(a, p - 2, p); }
constexpr lli MOD = 1e9 + 7;

int main() {
  lli N;
  input(N);
  vector<lli> p(N);
  input(p);
  lli cnt = 0;
  for (int i = 1; i < N - 1; ++i) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1] ||
        p[i - 1] > p[i] && p[i] > p[i + 1])
      cnt++;
  }
  print(cnt);
}

Measured memory_bytes: 256