#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 7;
int x[maxn], d[maxn], a[maxn], dp[maxn], xx[maxn], dd[maxn];
int main() {
  memset(dp, 0x3f, sizeof(dp));
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  stack<int> s;
  for (int i = n; i >= 1; i--) {
    while (!s.empty() && a[s.top()] > a[i]) s.pop();
    if (s.empty())
      x[i] = n + 1;
    else
      x[i] = s.top();
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = n; i >= 1; i--) {
    while (!s.empty() && a[s.top()] < a[i]) s.pop();
    if (s.empty())
      d[i] = n + 1;
    else
      d[i] = s.top();
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = 1; i <= n; i++) {
    while (!s.empty() && a[s.top()] < a[i]) s.pop();
    if (s.empty())
      dd[i] = 0;
    else
      dd[i] = s.top();
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = 1; i <= n; i++) {
    while (!s.empty() && a[s.top()] > a[i]) s.pop();
    if (s.empty())
      xx[i] = 0;
    else
      xx[i] = s.top();
    s.push(i);
  }
  dp[1] = 0;
  for (int i = 1; i <= n; i++) {
    if (xx[i]) dp[i] = min(dp[i], dp[xx[i]] + 1);
    if (dd[i]) dp[i] = min(dp[i], dp[dd[i]] + 1);
    if (x[i] != n + 1) {
      dp[x[i]] = min(dp[x[i]], dp[i] + 1);
    }
    if (d[i] != n + 1) {
      dp[d[i]] = min(dp[d[i]], dp[i] + 1);
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
