#include <bits/stdc++.h>
using namespace std;
vector<int> d[300005];
int f[300005], a[300005];
int pr[300005], pr1[300005];
int ne[300005], ne1[300005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    for (pr[i] = i - 1; pr[i] > 0 && a[pr[i]] < a[i]; pr[i] = pr[pr[i]])
      ;
    if (pr[i]) d[i].emplace_back(pr[i]);
    for (pr1[i] = i - 1; pr1[i] > 0 && a[pr1[i]] > a[i]; pr1[i] = pr1[pr1[i]])
      ;
    if (pr1[i]) d[i].emplace_back(pr1[i]);
  }
  for (int i = n; i >= 1; --i) {
    for (ne[i] = i + 1; ne[i] <= n && a[ne[i]] < a[i]; ne[i] = ne[ne[i]])
      ;
    if (ne[i] <= n) d[ne[i]].emplace_back(i);
    for (ne1[i] = i + 1; ne1[i] <= n && a[ne1[i]] > a[i]; ne1[i] = ne1[ne1[i]])
      ;
    if (ne1[i] <= n) d[ne1[i]].emplace_back(i);
  }
  fill(f + 1, f + n + 1, n + 5);
  f[1] = 0;
  for (int i = 2; i <= n; ++i) {
    for (auto &j : d[i]) f[i] = min(f[i], f[j] + 1);
  }
  cout << f[n];
}
