#include<stdio.h>
int a[30001],n,b[30001],tem,ans;
inline int mn()
{
freopen("diningb.in","r",stdin);
freopen("diningb.out","w",stdout);
scanf("%d",&n);
for (register int i=1;i<=n;++i) scanf("%d",&a[i]);
for (register int i=1;i<=n;++i)
if (a[i]==2) b[i]=++tem;
else b[i]=tem;
tem=0;
for (register int i=n;i>0;--i)
if (a[i]==1) b[i]+=++tem;
else b[i]+=tem;
ans=0xfffffff;
for (register int i=1;i<=n;++i)
if (b[i]<ans) ans=b[i];
printf("%d",ans-1);
return 0;
}
int ll=mn();
int main(){;}