{$M 64000,0,655360}

{$R-,Q-}

program Palin_Problem;{CH IOI2000 Day1}

const
  name1     =      'palin.in';
  name2     =      'palin.out';

var
  s         :      array[1..5100] of char;
  N         :      integer;
  ans       :      integer;

procedure init;
var inf : text;
    i   : integer;
begin
  assign(inf, name1);
  reset(inf);
  readln(inf, N);
  fillchar(s, sizeof(s), 0);
  for i := 1 to N do read(inf, s[i]);
  close(inf);
end;

procedure main;
var Dyx_2, Dyx_1, Dyx : array[1..5100] of integer;
    x, i, j : integer;
begin
  fillchar(Dyx_2, sizeof(Dyx_2), 0);
  fillchar(Dyx_1, sizeof(Dyx_1), 0);
  for i := 1 to N-1 do
    if s[i] <> s[i+1] then Dyx_1[i] := 1;

  for x := 3 to N do
    begin
      for i := 1 to N - x + 1 do
        if s[i] = s[i + x - 1]
          then Dyx[i] := Dyx_2[i + 1]
          else begin
                 if Dyx_1[i] < Dyx_1[i+1]
                   then Dyx[i] := Dyx_1[i]
                   else Dyx[i] := Dyx_1[i+1];
                 inc(Dyx[i]);
               end;

      Dyx_2 := Dyx_1;
      Dyx_1 := Dyx;
    end;

  ans := Dyx_1[1];
end;

procedure out;
var ouf : text;
begin
  assign(ouf, name2);
  rewrite(ouf);
  writeln(ouf, ans);
  close(ouf);
end;

begin
  init;
  main;
  out;
end.
