const
  maxn = 1000000;
var
  h : array[1..maxn] of integer;
  n, k, i, j, a : integer;
begin
  reset(input, 'stacks.in');
  rewrite(output, 'stacks.out');
  read(n);
  k := 0;
  j := 0;
  for i := 1 to n do begin
    read(a);
    if (i > 1) and (a = 0) then begin
      h[j] := h[j] + 1;
      j := j + 1;
      if (j > k) then begin
        j := j - 1;
        while (j > 1) and (h[j - 1] = h[j]) do begin
          j := j - 1;
        end;
      end;
    end else begin
      k := k + 1;
      h[k] := 1;
      if (k = 1) or (h[k - 1] <> h[k]) then begin
	      j := k;
	    end;
    end;
  end;
  writeln(h[1]);
end.