program savey;
var
data:array [1..1000] of boolean;
s:char;
n,i:integer;
step:longint;
function get(num:integer):longint;
var i,tmp:longint;
begin
if num=1 then begin
data[1]:=not(data[1]);
exit(1);
end
else if num=2 then begin
data[2]:=not(data[2]);
if data[1]=false then exit(get(1)+1) else exit(1);
end
else begin
tmp:=0;
if data[num-1]=false then tmp:=get(num-1);
for i:=num-2 downto 1 do if data[i]=true then tmp:=tmp+get(i);
data[num]:=not(data[num]);
exit (tmp+1);
end;
end;
begin
assign (input,'savey.in');
reset (input);
assign (output,'savey.out');
rewrite (output);
readln (n);
fillchar (data,sizeof(data),0);
for i:=1 to n do begin
read (s);
if s='1' then data[i]:=true;
end;
close (input);
step:=0;
for i:=n downto 1 do
if data[i] then
step:=step+get(i);
writeln (step);
close (output);
end.