There are n beautiful skyscrapers in New York, the height of the i-th one is h_i. Today some villains have set on fire first n - 1 of them, and now the only safety building is n-th skyscraper.

Let's call a jump from i-th skyscraper to j-th (i < j) discrete, if all skyscrapers between are strictly lower or higher than both of them. Formally, jump is discrete, if i < j and one of the following conditions satisfied: 

  * i + 1 = j 
  * max(h_{i + 1}, …, h_{j - 1}) < min(h_i, h_j) 
  * max(h_i, h_j) < min(h_{i + 1}, …, h_{j - 1}). 



At the moment, Vasya is staying on the first skyscraper and wants to live a little longer, so his goal is to reach n-th skyscraper with minimal count of discrete jumps. Help him with calcualting this number.

Input

The first line contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — total amount of skyscrapers.

The second line contains n integers h_1, h_2, …, h_n (1 ≤ h_i ≤ 10^9) — heights of skyscrapers.

Output

Print single number k — minimal amount of discrete jumps. We can show that an answer always exists.

Examples

Input


5
1 3 1 4 5


Output


3

Input


4
4 2 2 4


Output


1

Input


2
1 1


Output


1

Input


5
100 1 100 1 100


Output


2

Note

In the first testcase, Vasya can jump in the following way: 1 → 2 → 4 → 5.

In the second and third testcases, we can reach last skyscraper in one jump.

Sequence of jumps in the fourth testcase: 1 → 3 → 5.
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
clock_t START;
inline long double TIME() {
  return (long double)(clock() - START) / CLOCKS_PER_SEC;
}
void SHOW() {
  cout << fixed << setprecision(10);
  cout << TIME() << " SECONDS FROM START\n";
}
long double TL = 2.0;
long long calls = 0;
inline bool IS() {
  if (++calls == 1000) {
    calls = 0;
    if (TL - TIME() < 0.1) return true;
  }
  return false;
}
template <typename T1, typename T2>
inline bool amin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
inline bool amax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &u : v) is >> u;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto &u : v) os << u << ' ';
  return os;
}
long long hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937},
          mod = hash_mod[rnd() % 4];
long long hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
long long binpow(long long first, long long p) {
  long long res = 1;
  while (p) {
    if (p % 2) res = (res * first) % mod;
    first = (first * first) % mod;
    p /= 2;
  }
  return res;
}
const long long N = 1e6 + 7, NS = 2e3 + 7, lg = 20, sq = 550, inf = 2e9 + 7,
                SM = 1e2 + 7;
const long double eps = 1e-9;
struct st {
  vector<long long> t;
  long long n;
  void init(long long _n) {
    n = _n;
    t = vector<long long>(4 * n, inf);
  }
  long long get(long long v, long long l, long long r, long long vl,
                long long vr) {
    if (l >= vr || vl >= r) return inf;
    if (l >= vl && r <= vr) return t[v];
    long long m = (l + r) / 2;
    return min(get(2 * v, l, m, vl, vr), get(2 * v + 1, m, r, vl, vr));
  }
  void update(long long v, long long l, long long r, long long pos,
              long long first) {
    if (l > pos || r <= pos) return;
    if (l == r - 1) {
      t[v] = first;
      return;
    }
    long long m = (l + r) / 2;
    update(2 * v, l, m, pos, first);
    update(2 * v + 1, m, r, pos, first);
    t[v] = min(t[2 * v], t[2 * v + 1]);
  }
} MX, MN;
long long n, a[N], d[N];
long long BL[N], ML[N];
vector<long long> mx[N], mn[N];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  MX.init(n);
  MN.init(n);
  stack<long long> st;
  st.push(-1);
  for (long long i = n - 1; i >= 0; i--) {
    while (st.top() != -1 && a[st.top()] >= a[i]) {
      ML[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  while (st.top() != -1) {
    ML[st.top()] = -1;
    st.pop();
  }
  for (long long i = n - 1; i >= 0; i--) {
    while (st.top() != -1 && a[st.top()] <= a[i]) {
      BL[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  while (st.top() != -1) {
    BL[st.top()] = -1;
    st.pop();
  }
  for (long long i = 0; i < n; i++) {
    while (st.top() != -1 && a[st.top()] <= a[i]) {
      mx[i].push_back(st.top());
      st.pop();
    }
    st.push(i);
  }
  while (st.top() != -1) {
    st.pop();
  }
  for (long long i = 0; i < n; i++) {
    while (st.top() != -1 && a[st.top()] >= a[i]) {
      mn[i].push_back(st.top());
      st.pop();
    }
    st.push(i);
  }
  while (st.top() != -1) {
    st.pop();
  }
  for (long long i = 0; i < n; i++) {
    if (i) d[i] = d[i - 1] + 1;
    d[i] = min(d[i], MN.get(1, 0, n, ML[i], i) + 1);
    d[i] = min(d[i], MX.get(1, 0, n, BL[i], i) + 1);
    MN.update(1, 0, n, i, d[i]);
    MX.update(1, 0, n, i, d[i]);
    for (auto u : mn[i]) MN.update(1, 0, n, u, inf);
    for (auto u : mx[i]) MX.update(1, 0, n, u, inf);
  }
  cout << d[n - 1];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
