#include <bits/stdc++.h>
using namespace std;
const int maxN = (int) 1e5 + 6;
vector<int> dp(maxN, 1);
vector<int> a;
vector<int> mode(maxN);
bool comp(int i, int j) {
if (mode[j] == 0) {
if (a[i] > a[j]) {
mode[i] = 1;
return true;
}
if (a[j] < a[j]) {
mode[i] = 2;
return true;
}
return false;
}
if (mode[j] == 1) {
if (a[i] < a[j]) {
mode[i] = 2;
return true;
}
return false;
}
if (mode[j] == 2) {
if (a[i] > a[j]) {
mode[i] = 1;
return true;
}
return false;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int nsave = n;
for(int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
if (i == 0) a.push_back(tmp); else {
if (tmp == a[a.size() - 1]) continue; else a.push_back(tmp);
}
}
n = a.size();
int ans = 0;
for(int i = 0; i < n; i++) {
dp[i] = 1;
for(int j = 0; j < i; j++) {
if (comp(i, j) && dp[i] < dp[j] + 1) {
dp[i] = dp[j] + 1;
}
}
if (i == 0 || i == 1) ans++; else {
if (mode[i - 1] != mode[i]) ans++;
}
}
cout << nsave - ans;
return 0;
}