#include <cstdio>
using namespace std;
int a[30000],b[30000];
int main(void)
{
freopen("egroup.in","r",stdin);
freopen("egroup.out","w",stdout);
int i,j,n,temp,maxlen=0,l[4]={0};
scanf("%d\n",&n);
for (i=0;i<n;i++)
{
scanf("%d\n",&a[i]);
b[n-1-i]=a[i];
}
for (i=0;i<n;i++)
{
temp=0;
for (j=1;j<=a[i];j++)
if (l[j]>temp)
temp=l[j];
temp++;
l[a[i]]=temp;
}
for (i=1;i<=3;i++)
if (l[i]>maxlen)
maxlen=l[i];
l[1]=0;
l[2]=0;
l[3]=0;
for (i=0;i<n;i++)
{
temp=0;
for (j=1;j<=b[i];j++)
if (l[j]>temp)
temp=l[j];
temp++;
l[b[i]]=temp;
}
for (i=1;i<=3;i++)
if (l[i]>maxlen)
maxlen=l[i];
printf("%d\n",n-maxlen);
fclose(stdin);
fclose(stdout);
return(0);
}