program ex;
type
ss=array[1..5000]of char;
sz=array[0..5000,0..5000]of integer;
var
a,b:ss;
f:sz;
f1,f2:text;
n:integer;
procedure init;
var
i:integer;
begin
assign(f1,'palin.in');
assign(f2,'palin.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
for i:=1 to n do
b[n-i+1]:=a[i];
end;
procedure main;
var
i,j:integer;
begin
for i:=1 to n do
for j:=1 to n do
begin
if a[i]=b[j] then f[i,j]:=f[i-1,j-1]+1
else if f[i-1,j]>f[i,j-1] then f[i,j]:=f[i-1,j]
else f[i,j]:=f[i,j-1];
end;
writeln(f2,n-f[n,n]);
end;
begin
init;
main;
close(f2);
end.