#include <bits/stdc++.h>
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
using namespace std;
const long long maxn = 1e3 + 7;
const double eps = 1e-10;
const long long mod = 1e9 + 7;
long long dp[maxn][maxn];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  char s[maxn];
  long long n;
  cin >> n;
  cin >> s + 1;
  memset(dp, 0x3f, sizeof(dp));
  for (long long i = 1; i <= (long long)(n); i++) dp[i][i] = 1;
  for (long long len = 2; len <= n; len++) {
    for (long long l = 1; l + len - 1 <= n; l++) {
      long long r = l + len - 1;
      for (long long mid = l; mid < r; mid++) {
        if (s[l] == s[mid + 1] || s[mid] == s[mid + 1] || s[l] == s[r] ||
            s[mid] == s[r]) {
          dp[l][r] = min(dp[l][r], dp[l][mid] + dp[mid + 1][r] - 1);
        } else
          dp[l][r] = min(dp[l][r], dp[l][mid] + dp[mid + 1][r]);
      }
    }
  }
  cout << dp[1][n] << "\n";
}
