#include<bits/stdc++.h>
using namespace std;
int a[30005],b[30005];
int n,m,ans,xb;
int main()
{
freopen("diningb.in", "r", stdin);
freopen("diningb.out", "w", stdout);
xb=300005;
ans=xb;
cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++)
if (a[i]==2)
b[i]=++m;
else b[i]=m;
m=0;
for (int i=n;i>0;i--)
if (a[i]==1)
b[i]+=++m;
else b[i]+=m;
for (int i=1;i<=n;i++)
if (b[i]<ans)
ans=b[i];
cout<<ans-1<<endl;
return 0;
}