var n,i,j,k,head,tail:longint;
a,g,u:string;
c:char; fg:boolean;
d:array[0..100000]of string;
f:array[0..100000]of longint;
function check:boolean;
var i,j,k:longint;
begin
check:=true;
if g=u then begin fg:=true;exit; end;
for i:=head to tail do
if d[i]=g then begin check:=false;exit;end;
end;
procedure go;
begin
for i:=1 to n do
begin
if fg then exit;
g:=d[head];
if (i>2)and(g[i-2]='0')and(g[i-1]='1') then
begin
if g[i]='1' then
begin g[i]:='0';
if check then begin
if fg then exit;
inc(tail);d[tail]:=g;f[tail]:=f[head]+1;end;
end;
if g[i]='0' then
begin g[i]:='1';
if check then begin
if fg then exit;
inc(tail);d[tail]:=g;f[tail]:=f[head]+1;end;
end;
end;
if (i=2)and(g[i-1]='1') then
begin
if g[i]='1' then
begin g[i]:='0';
if check then begin
if fg then exit;
inc(tail);d[tail]:=g;f[tail]:=f[head]+1;end;
end;
if g[i]='0' then
begin g[i]:='1';
if check then begin
if fg then exit;
inc(tail);d[tail]:=g;f[tail]:=f[head]+1;end;
end;
end;
if (i=1)then begin
if g[i]='1' then
begin g[i]:='0';
if check then begin
if fg then exit;
inc(tail);d[tail]:=g;f[tail]:=f[head]+1;end;
end;
if g[i]='0' then
begin g[i]:='1';
if check then begin
if fg then exit;
inc(tail);d[tail]:=g;f[tail]:=f[head]+1;end;
end;
end;
end;
inc(head);
if fg then exit;
end;
Begin
assign(input,'savey.in');reset(input);
assign(output,'savey.out');rewrite(output);
readln(n);i:=0;a:='';u:='';
for i:=1 to n do u:=u+'0';
repeat
read(c);
if c='0' then begin inc(i);a:=a+'0';end;
if c='1' then begin inc(i);a:=a+c;end;
until eof;
head:=0;tail:=0;
fg:=false;
d[0]:=a; f[0]:=0;
repeat
go;
until (head>tail)or fg;
writeln(f[tail]);
close(input);close(output);
end.