#include <bits/stdc++.h>
using namespace std;
int n;
int a[105];
int head_to_tail[105];
int tail_to_head[105];
int ans;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
if (a[i] > a[j])
{
head_to_tail[i] = max(head_to_tail[i], head_to_tail[j] + 1);
}
}
}
for (int i = n; i; i--)
{
for (int j = n + 1; j > i; j--)
{
if (a[i] > a[j])
{
tail_to_head[i] = max(tail_to_head[i], tail_to_head[j] + 1);
}
}
}
for (int i = 1; i <= n; i++)
{
ans = max(head_to_tail[i] + tail_to_head[i] - 1, ans);
}
cout << n - ans << endl;
}