#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
vector<long long int> adj[300001];
bool visited[300001];
long long int dist[300001];
namespace seg1 {
vector<long long int> seg;
long long int single(long long int x) { return x; }
long long int neutral() { return INT_MIN; }
long long int merge(long long int a, long long int b) { return max(a, b); }
long long int query(long long int l, long long int r, long long int ql,
                    long long int qr, long long int i, long long int x) {
  if (l == r) return (seg[i] >= x && l >= ql) ? l : -1;
  long long int mid = (l + r) >> 1, at = -1;
  if (seg[i << 1] >= x && mid >= ql) at = query(l, mid, ql, qr, i << 1, x);
  if (at == -1) at = query(mid + 1, r, ql, qr, (i << 1) | 1, x);
  return at;
}
void build(long long int l, long long int r, long long int i) {
  if (l == r) {
    seg[i] = single(v[l]);
    return;
  }
  long long int mid = (l + r) >> 1;
  build(l, mid, i << 1);
  build(mid + 1, r, (i << 1) | 1);
  seg[i] = merge(seg[i << 1], seg[(i << 1) | 1]);
}
}  // namespace seg1
namespace seg2 {
vector<long long int> seg;
long long int single(long long int x) { return x; }
long long int neutral() { return INT_MAX; }
long long int merge(long long int a, long long int b) { return min(a, b); }
long long int query(long long int l, long long int r, long long int ql,
                    long long int qr, long long int i, long long int x) {
  if (l == r) return (seg[i] <= x && l >= ql) ? l : -1;
  long long int mid = (l + r) >> 1, at = -1;
  if (seg[i << 1] <= x && mid >= ql) at = query(l, mid, ql, qr, i << 1, x);
  if (at == -1) at = query(mid + 1, r, ql, qr, (i << 1) | 1, x);
  return at;
}
void build(long long int l, long long int r, long long int i) {
  if (l == r) {
    seg[i] = single(v[l]);
    return;
  }
  long long int mid = (l + r) >> 1;
  build(l, mid, i << 1);
  build(mid + 1, r, (i << 1) | 1);
  seg[i] = merge(seg[i << 1], seg[(i << 1) | 1]);
}
}  // namespace seg2
namespace seg3 {
vector<long long int> seg;
long long int single(long long int x) { return x; }
long long int neutral() { return INT_MIN; }
long long int merge(long long int a, long long int b) { return max(a, b); }
long long int query(long long int l, long long int r, long long int ql,
                    long long int qr, long long int i, long long int x) {
  if (l == r) return (seg[i] >= x && r <= qr) ? r : -1;
  long long int mid = (l + r) >> 1, at = -1;
  if (seg[(i << 1) | 1] >= x && mid <= qr)
    at = query(mid + 1, r, ql, qr, (i << 1) | 1, x);
  if (at == -1) at = query(l, mid, ql, qr, i << 1, x);
  return at;
}
void build(long long int l, long long int r, long long int i) {
  if (l == r) {
    seg[i] = single(v[l]);
    return;
  }
  long long int mid = (l + r) >> 1;
  build(l, mid, i << 1);
  build(mid + 1, r, (i << 1) | 1);
  seg[i] = merge(seg[i << 1], seg[(i << 1) | 1]);
}
}  // namespace seg3
namespace seg4 {
vector<long long int> seg;
long long int single(long long int x) { return x; }
long long int neutral() { return INT_MAX; }
long long int merge(long long int a, long long int b) { return min(a, b); }
long long int query(long long int l, long long int r, long long int ql,
                    long long int qr, long long int i, long long int x) {
  if (l == r) return (seg[i] <= x && r <= qr) ? r : -1;
  long long int mid = (l + r) >> 1, at = -1;
  if (seg[(i << 1) | 1] <= x && mid <= qr)
    at = query(mid + 1, r, ql, qr, (i << 1) | 1, x);
  if (at == -1) at = query(l, mid, ql, qr, i << 1, x);
  return at;
}
void build(long long int l, long long int r, long long int i) {
  if (l == r) {
    seg[i] = single(v[l]);
    return;
  }
  long long int mid = (l + r) >> 1;
  build(l, mid, i << 1);
  build(mid + 1, r, (i << 1) | 1);
  seg[i] = merge(seg[i << 1], seg[(i << 1) | 1]);
}
}  // namespace seg4
void bfs(long long int s) {
  dist[s] = 0;
  queue<long long int> q;
  q.push(s);
  while (!q.empty()) {
    long long int v = q.front();
    q.pop();
    if (visited[v]) continue;
    visited[v] = true;
    for (auto const &u : adj[v]) {
      if (dist[u] > dist[v] + 1) {
        dist[u] = dist[v] + 1;
        q.push(u);
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  v.resize(n);
  seg1::seg.resize(4 * 300001);
  seg2::seg.resize(4 * 300001);
  seg3::seg.resize(4 * 300001);
  seg4::seg.resize(4 * 300001);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  seg1::build(0, n - 1, 1);
  seg2::build(0, n - 1, 1);
  seg3::build(0, n - 1, 1);
  seg4::build(0, n - 1, 1);
  for (long long int i = 0; i < n; i++) {
    dist[i] = INT_MAX;
    long long int curr;
    curr = -1;
    if (i + 1 < n) curr = seg1::query(0, n - 1, i + 1, n - 1, 1, v[i]);
    if (curr != -1) adj[i].push_back(curr);
    curr = -1;
    if (i + 1 < n) curr = seg2::query(0, n - 1, i + 1, n - 1, 1, v[i]);
    if (curr != -1) adj[i].push_back(curr);
    curr = -1;
    if (i - 1 >= 0) curr = seg3::query(0, n - 1, 0, i - 1, 1, v[i]);
    if (curr != -1) adj[curr].push_back(i);
    curr = -1;
    if (i - 1 >= 0) curr = seg4::query(0, n - 1, 0, i - 1, 1, v[i]);
    if (curr != -1) adj[curr].push_back(i);
  }
  bfs(0);
  cout << dist[n - 1] << endl;
}
