{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+} {$M 16384,0,655360} program CHAIN; var f: text; N, i, count, _one: integer; k: longint; begin _one:=0; Assign (f, 'CHAIN.DAT'); Reset (f); Readln (f, N); for i:=1 to N do begin Read (f, k); if k=1 then inc (_one); end; Close (f); i:=0; if N>(_one*2) then i:=1; count:=N-_one-i; Assign (f, 'CHAIN.RES'); Rewrite (f); Writeln (f, count); Close (f); end.