#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int arr[5002];
int arr2[5002];
int temp[5002];
#define M 0x7fffffff
inline int min(int a,int b){return a>b?b:a;}
inline int mmin(int a,int b,int c){return a>min(b,c)?min(b,c):a;}
int n;
char s[5002];
void solve()
{
memset(arr,0,sizeof(arr));
memset(arr2,0,sizeof(arr2));
memset(temp,0,sizeof(temp));
bool flag = 0;
for(int j=1;j<n;j++)
{
for(int i=0;i<n-j;i++)
{
if(j==1)
{
arr[i]= (s[i]==s[i+j]?0:1);
}
else
{
int a = M;
int b = arr[i+1]+1;
int c = arr[i]+1;
if(s[i]==s[i+j]) a = arr2[i+1];
temp[i]=mmin(a,b,c);
flag = 1;
}
}
if(flag)
for(int i=0;i<n;i++)
{
arr2[i]=arr[i];
arr[i]=temp[i];
}
}
printf("%d\n",arr[0]);
}
int main()
{
while(cin>>n)
{
scanf("%s",s);
n=strlen(s);
solve();
}
return 0;
}