#include <bits/stdc++.h>
using namespace std;
int N;
int dp[501][501][26];
int vis[501][501][26];
int vet[501];
vector<int> G[501];
vector<int>::iterator it;
vector<pair<int, int> > V;
void comprime() {
  int a = vet[0], b = 1;
  V.clear();
  for (int i = 1; i < N; i++) {
    if (a == vet[i])
      b++;
    else {
      G[a].push_back(V.size());
      V.push_back(make_pair(a, b));
      a = vet[i];
      b = 1;
    }
  }
  G[a].push_back(V.size());
  V.push_back(make_pair(a, b));
  V.push_back(make_pair(0, 0));
}
int solve(int start, int end, int sz) {
  int cor, z;
  if (start == end) return sz > 0;
  if (start > end) return 101001001;
  if (vis[start][end][sz] == 1) return dp[start][end][sz];
  vis[start][end][sz] = 1;
  cor = V[start].first;
  dp[start][end][sz] = 1 + solve(start + 1, end, 0);
  it = lower_bound(G[cor].begin(), G[cor].end(), start + 2);
  if (it != G[cor].end() && *it <= end) {
    z = it - G[cor].begin();
    for (int i = z; i < (int)G[cor].size(); i++) {
      z = G[cor][i];
      if (z > end) break;
      dp[start][end][sz] =
          min(dp[start][end][sz],
              solve(z, end, sz + V[start].second) + solve(start + 1, z, 0));
    }
  }
  return dp[start][end][sz];
}
char str[501];
int main() {
  scanf("%d", &N);
  scanf("%s", str);
  for (int i = 0; i < N; i++) vet[i] = str[i] - 'a';
  comprime();
  printf("%d\n", solve(0, V.size() - 1, 0));
  return 0;
}
