#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6 + 7;
const int INF = (int)1e9 + 7;
int dp[MAXN];
int a[MAXN];
int bi[MAXN], sm[MAXN];
stack<int> st;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (int)1; i <= (int)n; i++) {
    scanf("%d", &a[i]);
  }
  st.push(n + 1);
  a[n + 1] = INF;
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && a[st.top()] <= a[i]) {
      st.pop();
    }
    bi[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  st.push(n + 1);
  a[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && a[st.top()] >= a[i]) {
      st.pop();
    }
    sm[i] = st.top();
    st.push(i);
  }
  for (int i = (int)1; i <= (int)n; i++) dp[i] = INF;
  dp[1] = 0;
  for (int i = (int)1; i <= (int)n - 1; i++) {
    if (a[i + 1] == a[i])
      dp[i + 1] = min(dp[i] + 1, dp[i + 1]);
    else if (a[i] > a[i + 1]) {
      int now = i + 1;
      while (now != n + 1 && a[now] < a[i]) {
        dp[now] = min(dp[now], dp[i] + 1);
        now = bi[now];
      }
      dp[now] = min(dp[now], dp[i] + 1);
    } else {
      int now = i + 1;
      while (now != n + 1 && a[now] > a[i]) {
        dp[now] = min(dp[now], dp[i] + 1);
        now = sm[now];
      }
      dp[now] = min(dp[now], dp[i] + 1);
    }
  }
  printf("%d\n", dp[n]);
}
