var
	a : array[0..1000031] of longint;
	q, tmp, i, n, st, tek : longint;
begin
	reset(input, 'stacks.in');
	rewrite(output, 'stacks.out');
	readln(n);
	q := 0;
	a[1] := 1;
	read(tmp);
	tek := 1;
	for i := 2 to n do
	begin
		read(st);
		if (st > 0) then 
		begin
			inc(tek);
			a[tek] := 1;
			q := tek;
		end;
		if (st = 0) then
		begin
			if tek = 1 then	inc(a[tek])
			else 
			begin
				while (q > 1) and (a[q] = a[q - 1]) do dec(q);
				inc(a[q]);
			end;
		end;
	end;
	writeln(a[1]);
end.

	