#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e2 + 69, INF = 1e9;
long long n;
string t, s = "0";
long long dp[MAXN][MAXN], dp2[MAXN][MAXN];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t;
  s += t[0];
  for (long long i = 1; i < t.size(); i++)
    if (t[i] != t[i - 1]) s += t[i];
  n = s.size() - 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = i; j <= n; j++)
      dp[i][j] = dp2[i][j] = (j == i ? 1 : INF);
  for (long long len = 2; len <= n; len++) {
    for (long long l = 1; l + len - 1 <= n; l++) {
      long long r = l + len - 1;
      if (s[l] == s[r]) dp[l][r] = dp[l + 1][r - 1] + 1;
      for (long long mid = l; mid < r; mid++) {
        dp[l][r] = min(dp[l][r], dp[l][mid] + dp[mid + 1][r]);
      }
      dp2[l][r] = dp[l][r];
      if (s[l] == s[r]) {
        dp2[l][r]--;
        for (long long mid = l + 1; mid < r; mid++) {
          if (s[mid] == s[l]) {
            dp2[l][r] = min(dp2[l][r], dp2[l][mid] + dp2[mid][r]);
          }
        }
        dp[l][r] = min(dp[l][r], dp2[l][r] + 1);
      }
    }
  }
  cout << dp[1][n];
}
