#include <bits/stdc++.h>
using namespace std;
const long long maxm = 3e5 + 5;
long long a[maxm];
long long d[maxm];
long long n;
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  stack<long long> s, ss;
  s.push(1);
  ss.push(1);
  d[1] = 0;
  for (long long i = 2; i <= n; i++) {
    d[i] = d[i - 1] + 1;
    while (!s.empty() && a[i] >= a[s.top()]) {
      long long x = a[s.top()];
      s.pop();
      if (a[i] != x && !s.empty()) {
        d[i] = min(d[i], d[s.top()] + 1);
      }
    }
    while (!ss.empty() && a[i] <= a[ss.top()]) {
      long long x = a[ss.top()];
      ss.pop();
      if (a[i] != x && !ss.empty()) {
        d[i] = min(d[i], d[ss.top()] + 1);
      }
    }
    s.push(i);
    ss.push(i);
  }
  cout << d[n] << endl;
  return 0;
}
