#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int dp[maxn][maxn];
char word[maxn];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", word + 1);
  for (int len = 1; len <= n; len++) {
    for (int l = 1; len + l - 1 <= n; l++) {
      int r = len + l - 1;
      if (word[r] == word[l]) {
        dp[l][r] = dp[l + 1][r - 1] + 1;
      } else {
        dp[l][r] = min(dp[l + 1][r], dp[l][r - 1]) + 1;
      }
      for (int k = l + 1; k <= r - 1; k++) {
        dp[l][r] = min(dp[l][k] + dp[k][r] - 1, dp[l][r]);
      }
    }
  }
  printf("%d\n", dp[1][n]);
  return 0;
}
