#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream fin("privc.in");
ofstream fout("privc.out");
int n,l[1001]={0},t[1001]={0},f[1001]={0},a1,a2,a3,m,i,j,sum=0,temp;
fin>>n;
for (i=1;i<=n;i++)
{
fin>>l[i];
if (l[i]==1)
a1++;
else
if (l[i]==2)
a2++;
else
if (l[i]==3)
a3++;
}
for (i=1;i<=a1;i++)
t[i]=1;
for (i=a1+1;i<=a2+a1+1;i++)
t[i]=2;
for (i=n-a3+1;i<=n;i++)
t[i]=3;
m=0;
for (i=1;i<=n;i++)
if (l[i]!=t[i])
{
m++;
f[m]=i;
}
for (int i=1;i<=n-1;i++)
for(int j=i;j<=n;j++)
if ((t[f[j]]==l[f[i]])&&(t[f[i]]==l[f[j]])&&(l[f[j]]!=t[f[j]])&&(l[f[i]]!=t[f[i]]))
{
temp=l[f[j]];
l[f[j]]=l[f[i]];
l[f[i]]=temp;
sum++;
}
for (i=1;i<m;i++)
for (j=i;j<=m;j++)
{
if ((t[f[i]]==l[f[j]])&&(l[f[j]]!=t[f[j]])&&(l[f[i]]!=t[f[i]]))
{
temp=l[f[j]];
l[f[j]]=l[f[i]];
l[f[i]]=temp;
sum++;
break;
}
}
fout<<sum;
fin.close();
fout.close();
return 0;
}