program bing;
type
zc=array[0..5000] of char;
var
f1,f2:text;
n:longint;
s:zc;
m,min,i:longint;
procedure init;
var
i,j:longint;
begin
assign(f1,'palin.in');reset(f1);
assign(f2,'palin.out');rewrite(F2);
readln(f1,n);
for i:=1 to n do read(f1,s[i]);
min:=10000;
end;
procedure nb(x,y:longint);
var
i,j:longint;
begin
i:=x;j:=y;m:=0;
repeat
while (s[i]=s[j])and(i>0) do begin dec(i);inc(j);end;
if i=0 then
begin m:=m+n-j+1;
if m<min then min:=m;end
else inc(m,2);
dec(i);inc(j);
until i<0;
end;
begin
init;
for i:=1 to n do
begin
nb(i,i);
if s[i]=s[i+1] then nb(i,i+1);
end;
write(f2,min);
close(f1);close(F2);
end.