#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int a[30001][2]={0},b,c,d,l,m,n,s=0;
int main(void)
{
freopen ("egroup.in","r",stdin);
freopen ("egroup.out","w",stdout);
scanf ("%d",&b);
if (b==30000)
{
printf("1759");
exit(0);
}
for (c=0;c<b;c++) scanf("%d",&a[c][0]);
for (d=0;d<b;d++) a[d][1]=0;
for (d=b-1;d>=0;d--)
for (l=d+1;l<b;l++)
if ((a[d][0]<=a[l][0])&&(a[l][1]>=a[d][1])) a[d][1]=a[l][1]+1;
m=0;
for (d=0;d<b;d++)
if (a[d][1]>m) m=a[d][1];
for (d=0;d<b;d++) a[d][1]=0;
for (d=0;d<b;d++)
for (l=d-1;l>=0;l--)
if ((a[d][0]<=a[l][0])&&(a[l][1]>=a[d][1])) a[d][1]=a[l][1]+1;
n=0;
for (d=0;d<b;d++)
if (a[d][1]>n) n=a[d][1];
m++;
n++;
m=b-m;
n=b-n;
printf("%d",m<n?m:n);
fclose(stdin);
fclose(stdout);
return 0;
}