#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 50;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int up[MAXN], down[MAXN];
int top1 = 0, top2 = 0;
int h[MAXN];
int dp[MAXN];
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> h[i], dp[i] = inf;
  dp[1] = 0;
  up[++top1] = 1;
  down[++top2] = 1;
  for (int i = 2; i <= n; i++) {
    while (h[i] < h[up[top1]] && top1) {
      dp[i] = min(dp[i], dp[up[top1]] + 1);
      top1--;
    }
    if (top1) dp[i] = min(dp[i], dp[up[top1]] + 1);
    while (h[i] == h[up[top1]] && top1) {
      top1--;
    }
    up[++top1] = i;
    while (h[i] > h[down[top2]] && top2) {
      dp[i] = min(dp[i], dp[down[top2]] + 1);
      top2--;
    }
    if (top2) dp[i] = min(dp[i], dp[down[top2]] + 1);
    while (h[i] == h[down[top2]] && top2) {
      top2--;
    }
    down[++top2] = i;
  }
  cout << dp[n] << endl;
  return 0;
}
