/*
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;
}
