program MayLava;
var
c:array[1..5000]of char;
a:array[1..5000,1..5000]of integer;
n:integer;
procedure start;
var
f:text;
i:longint;
begin
assign(f,'palin.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,c[i]);
close(f);
fillchar(a,sizeof(a),0);
end;
procedure main;
var
i,j,x:longint;
begin
for i:=2 to n do begin
for j:=1 to (n-i+1) do begin
if a[j,i-1]<=a[j+1,i-1] then x:=j else x:=j+1;
if c[j]<>c[i+j-1] then
a[j,i]:=a[x,i-1]+1
else begin
a[j,i]:=a[x,i-1]-1;
if a[j,i]<0 then a[j,i]:=0;
end;
end;
end;
end;
procedure print;
var
f:text;
begin
assign(f,'palin.out');
rewrite(f);
writeln(f,a[1,n]);
close(f);
end;
BEGIN
start;
main;
print;
END.