program savey(input,output);
type
re=record
deep,n:longint;
end;
var
n,i,len,dp,rec:longint;
ch:char;
boo:array[0..16777216]of boolean;
q:array[1..1000000]of re;
function expand(a:re):boolean;
var
i,t:longint;
begin
t:=a.n xor (1 shl (n-1));
if t=0 then
exit(true);
if (t<16777216) and not(boo[t]) then
begin
inc(len);
boo[t]:=true;
q[len].deep:=a.deep+1;
q[len].n:=t;
end;
for i:=n-1 downto 1 do
if a.n shr i=1 then
begin
t:=a.n xor (1 shl (i-1));
if t=0 then
exit(true);
if (t<16777216) and not(boo[t]) then
begin
inc(len);
boo[t]:=true;
q[len].deep:=a.deep+1;
q[len].n:=t;
end;
end
else if a.n shr i>1 then
break;
exit(false);
end;
begin
assign(input,'savey.in');
reset(input);
assign(output,'savey.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
read(ch);
rec:=rec shl 1;
if ch='1' then
rec:=rec+1;
read(ch);
end;
if rec=0 then
begin
writeln(0);
close(input);
close(output);
halt;
end;
q[1].n:=rec;
q[1].deep:=0;
if (rec<16777216) then
boo[rec]:=true;
i:=1;
dp:=0;
len:=1;
repeat
while q[i].deep=dp do
begin
if expand(q[i]) then
begin
writeln(dp+1);
close(input);
close(output);
halt;
end;
inc(i);
end;
inc(dp);
until 1=2;
end.