var
a : array [1..1000] of longint;
b : array [1..3] of longint;
i,n,k : longint;
procedure Swap(x,y,z:longint);
var
i,j,t : longint;
begin
i:=1;
j:=n;
while (i<=n) and (j>=1) and (i<j) and (i<=z) do
begin
while (i<=n) and (a[i]<>x) do inc(i);
while (j>=1) and (a[j]<>y) do dec(j);
if (i<j) and (i<=z)
then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i); dec(j);
inc(k);
end;
end;
end;
begin
readln(n);
for i:=1 to 3 do b[i]:=0;
for i:=1 to n do
begin
read(a[i]);
inc(b[a[i]]);
end;
Swap(3,1,b[1]);
Swap(2,1,b[1]);
Swap(3,2,b[1]+b[2]);
writeln(k);
end.
a : array [1..1000] of longint;
b : array [1..3] of longint;
i,n,k : longint;
procedure Swap(x,y,z:longint);
var
i,j,t : longint;
begin
i:=1;
j:=n;
while (i<=n) and (j>=1) and (i<j) and (i<=z) do
begin
while (i<=n) and (a[i]<>x) do inc(i);
while (j>=1) and (a[j]<>y) do dec(j);
if (i<j) and (i<=z)
then begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
inc(i); dec(j);
inc(k);
end;
end;
end;
begin
readln(n);
for i:=1 to 3 do b[i]:=0;
for i:=1 to n do
begin
read(a[i]);
inc(b[a[i]]);
end;
Swap(3,1,b[1]);
Swap(2,1,b[1]);
Swap(3,2,b[1]+b[2]);
writeln(k);
end.