program xmz;
var
cost:array[0..5000,0..5000]of integer;
st:array[1..5000]of char;
a,b,n:integer;
f1,f2:text;
begin
assign(f1,'palin.in');assign(f2,'palin.out');
reset(f1);rewrite(f2);
readln(f1,n);
for a:=1 to n do
read(f1,st[a]);
for b:=2 to n do
for a:=1to n+1-b do
begin
if st[a]=st[a+b-1] then
cost[a,b]:=cost[a+1,b-2];
if st[a]<>st[a+b-1] then
if cost[a,b-1]>cost[a+1,b-1] then cost[a,b]:=cost[a+1,b-1]+1
else cost[a,b]:=cost[a,b-1]+1;
end;
writeln(f2,cost[1,n]);
close(f1);close(f2);
end.