/*
ID: untamed
PROG: IOIPALIN
LANG: C++
*/
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<limits>
#include<climits>
#include<cmath>
#include<functional>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef short int i16;
typedef unsigned long long int u64;
typedef unsigned int u32;
typedef unsigned short int u16;
typedef unsigned char u8;
const int N = 5200;
int dp[N][N];
char s[N];
int n;
int main()
{
scanf("%d\n%s", &n, s+1);
int i,from,to;
for(i=1;i<=n;i++)
{
dp[i][i]=0;
}
for(i=1;i<n;i++)
{
if(s[i]==s[i+1])
dp[i][i+1]=0;
else
dp[i][i+1]=1;
}
for(i=2;i<=n;i++)
{
for(from=1;(to=from+i)<=n;from++)
{
if(s[from]==s[to])
dp[from][to]=dp[from+1][to-1];
else
dp[from][to]=1+min(dp[from+1][to],dp[from][to-1]);
}
}
printf("%d\n", dp[1][n]);
return 0;
}
LyoKSUQ6IHVudGFtZWQKUFJPRzogSU9JUEFMSU4KTEFORzogQysrCiovCgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTxzdHJpbmc+CiNpbmNsdWRlPGNzdHJpbmc+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8c3RhY2s+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxkZXF1ZT4KI2luY2x1ZGU8bWFwPgojaW5jbHVkZTxzZXQ+CiNpbmNsdWRlPGxpbWl0cz4KI2luY2x1ZGU8Y2xpbWl0cz4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPGZ1bmN0aW9uYWw+CiNpbmNsdWRlPGN0aW1lPgojaW5jbHVkZTxjc3RkbGliPgojaW5jbHVkZTxmc3RyZWFtPgojaW5jbHVkZTx0eXBlaW5mbz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7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