#include<iostream>
#include<cstdio>
using namespace std;
int n,ans;
int data[40005];
int f[40005];
int g[40005];
int max(int x,int y);
int max(int x,int y)
{
if (x>y) return x;else return y;
}
int main()
{
freopen("egroup.in","r",stdin);
freopen("egroup.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&data[i]);
f[i]=1;
g[i]=1;
}
for (int i=2;i<=n;i++)
{
for (int j=i-1;j>=1;j--)
{
if (data[i]>=data[j])
{
f[i]=max(f[i],f[j]+1);
}
}
}
for (int i=n-1;i>=1;i--)
{
for (int j=i+1;j<=n;j++)
{
if (data[i]>=data[j])
{
g[i]=max(g[i],g[j]+1);
}
}
ans=max(g[i],ans);
}
printf("%d",n-ans);
return 0;
}