#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, f1, f2;
int dp[N], h[N];
stack<int> s1, s2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
  memset(dp, 0x3f, sizeof dp);
  s1.push(1), s2.push(1), dp[1] = 0;
  for (int i = 2; i <= n; ++i) {
    f1 = f2 = 0;
    while (s1.size() && h[s1.top()] >= h[i]) {
      if (h[s1.top()] == h[i]) f1 = 1;
      dp[i] = min(dp[i], dp[s1.top()] + 1);
      s1.pop();
    }
    if (s1.size() && !f1) dp[i] = min(dp[i], dp[s1.top()] + 1);
    while (s2.size() && h[s2.top()] <= h[i]) {
      if (h[s2.top()] == h[i]) f2 = 1;
      dp[i] = min(dp[i], dp[s2.top()] + 1);
      s2.pop();
    }
    if (s2.size() && !f2) dp[i] = min(dp[i], dp[s2.top()] + 1);
    s1.push(i);
    s2.push(i);
  }
  printf("%d\n", dp[n]);
  return 0;
}
