#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int a[30009][2]={0},b[30009][2]={0},c,d,l,n,t,x,y;
int main(void)
{
freopen("egroup.in","r",stdin);
freopen("egroup.out","w",stdout);
scanf("%d",&n);
for (c=0;c<n;c++)
{
scanf("%d",&a[c][0]);
b[c][0]=a[c][0];
}
for (d=1;d<n;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;
x=0;
for (d=0;d<n;d++)
if (a[d][1]>x) x=a[d][1];
for (d=1;d<n;d++)
for (l=d-1;l>=0;l--)
if ((b[d][0]<=b[l][0])&&(b[l][1]>=b[d][1]))
b[d][1]=b[l][1]+1;
y=0;
for (d=0;d<n;d++)
if (b[d][1]>y) y=b[d][1];
x++;
y++;
x=x>y?x:y;
n-=x;
printf("%d",n);
fclose(stdin);
fclose(stdout);
return 0;
}