program xxxx;
var n,w,i:longint;
a:array[1..1000] of longint;
procedure kai(k:longint);
begin
if (k=1)or((k=2)and(a[1]=1))or((a[k-1]=1)and(a[k-2]=0)) then
begin
if a[k]=1 then
a[k]:=0
else
a[k]:=1;
inc(w);
end
else
begin
if k=2 then
begin
if a[1]=0 then
kai(1);
end
else
begin
if a[k-1]=0 then
kai(k-1);
if a[k-2]=1 then
kai(k-2);
if a[k]=1 then
a[k]:=0
else
a[k]:=1;
inc(w);
end;
end;
end;
begin
assign(input,'savey.in');
reset(input);
assign(output,'savey.out');
rewrite(output);
w:=1;
read(n);
for i:=1 to n do
read(a[i]);
repeat
begin
if a[n]=0 then
n:=n-1
else
begin
kai(n);
n:=n-1;
end;
end
until n<=0;
write(w);
close(input);
close(output);
end.