#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int n;
    string ll;
    cin >> n >> ll;
    vector<vector<int>> D(n+1);
    D[0] = vector<int>(n,0);
    D[1] = vector<int>(n,1);

    for(int d=2; d<=n; d++) {
        vector<int> &curD = D[d];
        for(int i=0; i<n-d; i++) {
            int minval = 1+D[d-1][i+1];
            for(int k=2; k<=i; k++) {
                int curval = D[k][i] + D[d-k][i+k];
                if(curval<minval) {
                    minval = curval;
                }
            }
            if(ll[i]==ll[i+d-1] && minval>D[d-2][i+1]) {
                minval = D[d-2][i+1]
            }
            curD.push_back(minval);
        }
    }
    cout << D[n][0];
}
