#include <bits/stdc++.h>
using namespace std;
const int N = 300100, inf = 1e9;
long long h[N];
int dp[N], n;
int low[N], maxlow = 1;
int high[N], maxhigh = 1;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> h[i];
  for (int i = 0; i < n; ++i) dp[i] = inf;
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    int mnlow = inf;
    while (maxlow && h[low[maxlow - 1]] > h[i])
      mnlow = min(mnlow, dp[low[--maxlow]]);
    if (maxlow) mnlow = min(mnlow, dp[low[maxlow - 1]]);
    if (!maxlow || h[low[maxlow - 1]] < h[i])
      low[maxlow++] = i;
    else
      low[maxlow - 1] = i;
    int mnhigh = inf;
    while (maxhigh && h[high[maxhigh - 1]] < h[i])
      mnhigh = min(mnhigh, dp[high[--maxhigh]]);
    if (maxhigh) mnhigh = min(mnhigh, dp[high[maxhigh - 1]]);
    if (!maxhigh || h[high[maxhigh - 1]] > h[i])
      high[maxhigh++] = i;
    else
      high[maxhigh - 1] = i;
    dp[i] = min(mnlow, mnhigh) + 1;
  }
  cout << dp[n - 1] << endl;
}
