#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
stack<long long> down;
stack<long long> up;
int main() {
  long long n;
  cin >> n;
  long long a[N], dp[N];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  dp[1] = 0;
  down.push(1);
  up.push(1);
  for (long long i = 2; i <= n; i++) {
    dp[i] = dp[i - 1] + 1;
    while (down.size() && a[i] >= a[down.top()]) {
      long long x = a[down.top()];
      down.pop();
      if (a[i] > x && down.size()) {
        dp[i] = min(dp[i], dp[down.top()] + 1);
      }
    }
    down.push(i);
    while (up.size() && a[i] <= a[up.top()]) {
      long long x = a[up.top()];
      up.pop();
      if (a[i] < x && up.size()) {
        dp[i] = min(dp[i], dp[up.top()] + 1);
      }
    }
    up.push(i);
  }
  printf("%d\n", dp[n]);
}
