include [HTML_REMOVED]
using namespace std;
int f[10005], n, sum, x[10005], a[10005], i, j;
int main()
{
cin >> n;
for(i = 1; i <= n; i)
{
cin >> a[i];
f[i] = 1;
x[i] = 1;
}
for (i = 1; i <= n; i)
for (j = i - 1; j >= 0; j–)
if (a[i] > a[j]) f[i] = max(f[i], f[j] + 1);
for (i = n; i > 0; i–)
for (j = i + 1; j <= n; j)
if(a[i] > a[j]) x[i] = max(x[i], x[j] + 1);
for (i = 2; i <= n; i)
f[i] = max(f[i], f[i - 1]);
for (i = n - 1; i > 0; i–)
x[i] = max(x[i], x[i + 1]);
for (i = 1; i <= n; i++)
sum = max(sum, f[i] + x[i] - 1);
cout << n - sum << endl;
return 0;
}