#include <bits/stdc++.h>
using namespace std;
long long const MAXN = 5e2 + 8;
long long const INF = 1e12 + 8;
long long const delta = 1000000007;
long long dp[MAXN][MAXN];
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  s += 'a';
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) dp[i][j] = INF;
  }
  for (long long i = 0; i < n; i++) dp[i][i] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < n; j++) {
      if (j + i - 1 >= n) break;
      long long temp = INF;
      for (long long k = j; k <= j + i - 2; k++) {
        long long x = dp[j][k] + dp[k + 1][j + i - 1];
        if (s[j] == s[k + 1] || s[j] == s[j + i - 1] || s[k] == s[k + 1] ||
            s[k] == s[j + i - 1])
          x--;
        temp = min(temp, x);
      }
      dp[j][j + i - 1] = min(dp[j][j + i - 1], temp);
      long long l = j, r = j + i - 1;
      if (s[l] != s[r]) continue;
      while (s[l] == s[l + 1] && l + 1 <= j + i - 1) l++;
      while (s[r] == s[r - 1] && r - 1 >= l) r--;
      if (l == r)
        dp[j][j + i - 1] = 1;
      else
        dp[j][j + i - 1] = min(dp[j][j + i - 1], 1 + dp[l + 1][r - 1]);
    }
  }
  cout << dp[0][n - 1];
  return 0;
}
