/*
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[0][1]=1;
}
for(i=1;i<n;i++)
{
if(s[i]==s[i+1])
dp[1][i]=0;
else
dp[1][i]=1;
}
for(i=2;i<=n;i++)
{
for(from=1;(to=from+i)<=n;from++)
{
if(s[from]==s[to])
dp[i][from]=dp[i-2][from+1];
else
dp[i][from]=1+min(dp[i-1][from],dp[i-1][from+1]);
}
}
printf("%d\n", dp[n-1][1]);
return 0;
}
LyoKSUQ6IHVudGFtZWQKUFJPRzogSU9JUEFMSU4KTEFORzogQysrCiovCgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8YWxnb3JpdGhtPgojaW5jbHVkZTxzdHJpbmc+CiNpbmNsdWRlPGNzdHJpbmc+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8c3RhY2s+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxkZXF1ZT4KI2luY2x1ZGU8bWFwPgojaW5jbHVkZTxzZXQ+CiNpbmNsdWRlPGxpbWl0cz4KI2luY2x1ZGU8Y2xpbWl0cz4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPGZ1bmN0aW9uYWw+CiNpbmNsdWRlPGN0aW1lPgojaW5jbHVkZTxjc3RkbGliPgojaW5jbHVkZTxmc3RyZWFtPgojaW5jbHVkZTx0eXBlaW5mbz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7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