#include <bits/stdc++.h>
using namespace std;
int h[300001], dp[300001];
int lle[300001], rle[300001], lge[300001], rge[300001];
vector<int> res[300001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    cin >> h[i];
    dp[i] = 0x3F3F3F3F;
  }
  dp[0] = 0;
  vector<pair<int, int> > st;
  for (int i = 0; i < (n); i++) {
    while (!st.empty() && st.back().first < h[i]) {
      st.pop_back();
    }
    if (st.empty())
      lge[i] = -1;
    else
      lge[i] = st.back().second;
    st.push_back({h[i], i});
  }
  st.clear();
  for (int i = 0; i < (n); i++) {
    while (!st.empty() && st.back().first > h[i]) {
      st.pop_back();
    }
    if (st.empty())
      lle[i] = -1;
    else
      lle[i] = st.back().second;
    st.push_back({h[i], i});
  }
  st.clear();
  for (int i = n - 1; i >= 0; i--) {
    while (!st.empty() && st.back().first < h[i]) {
      st.pop_back();
    }
    if (st.empty())
      rge[i] = -1;
    else
      rge[i] = st.back().second;
    st.push_back({h[i], i});
  }
  st.clear();
  for (int i = n - 1; i >= 0; i--) {
    while (!st.empty() && st.back().first > h[i]) {
      st.pop_back();
    }
    if (st.empty())
      rle[i] = -1;
    else
      rle[i] = st.back().second;
    st.push_back({h[i], i});
  }
  st.clear();
  for (int i = 0; i < (n); i++) {
    if (rle[i] != -1) res[i].push_back(rle[i]);
    if (rge[i] != -1) res[i].push_back(rge[i]);
    if (lle[i] != -1) res[lle[i]].push_back(i);
    if (lge[i] != -1) res[lge[i]].push_back(i);
  }
  for (int i = 0; i < (n); i++) {
    for (int to : res[i]) {
      dp[to] = min(dp[to], dp[i] + 1);
    }
  }
  cout << dp[n - 1] << endl;
}
