program aa;
var
l:char;
f1,f2:text;
i,j:integer;
k:integer;
a,b,s:integer;
ar:array[1..1000] of integer;
begin
k:=0;
s:=0;
assign(f1,'savey.in');assign(f2,'savey.out');
reset(f1);
rewrite(f2);
readln(f1,a);
for i:=1 to a-1 do
read(f1,ar[i],l);
read(f1,ar[a]);
for i:=1 to a do
if ar[j]=0 then inc(s);
if s=a then
write(f2,0) else
begin
if ar[a]=0 then
begin
for i:=1 to a-1 do
if ar[i]=0 then
inc(k);
b:=k+a-3+(a-2)*2;
write(f2,b);
end;
end;
close(f1);
close(f2);
end.