#include <bits/stdc++.h>
using namespace std;
int res[300005];
int a[300005];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; ++i) cin >> a[i], res[i] = i - 1;
    stack<int> l, r;
    l.push(1);
    r.push(1);
    for (int i = 2; i <= n; ++i) {
      res[i] = min(res[i - 1] + 1, res[i]);
      bool f = 1;
      while (l.size() && a[l.top()] <= a[i]) {
        int lst = l.top();
        l.pop();
        if (a[lst] == a[i]) f = 0;
        if (l.size() && f) res[i] = min(res[i], res[l.top()] + 1);
      }
      f = 1;
      while (r.size() && a[r.top()] >= a[i]) {
        int lst = r.top();
        r.pop();
        if (a[lst] == a[i]) f = 0;
        if (r.size() && f) res[i] = min(res[i], res[r.top()] + 1);
      }
      l.push(i);
      r.push(i);
    }
    cout << res[n] << endl;
  }
}
