#include <bits/stdc++.h>
using namespace std;
long long int dp[1000][1000];
string s;
string removeDuplicates(string second) {
  int n = second.length();
  string c = "";
  if (n < 2) return second;
  int j = 0;
  c = c + second[0];
  for (int i = 1; i < n; i++) {
    if (second[i] != second[i - 1]) {
      c = c + second[i];
    }
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int len;
  cin >> len;
  string t;
  cin >> t;
  s = removeDuplicates(t);
  long long int n = s.length();
  for (long long int i = 0; i < n + 10; i++) {
    for (long long int j = 0; j < n + 10; j++) dp[i][j] = 0;
  }
  for (long long int i = 0; i < n + 10; i++) dp[i][i] = 1;
  char temp;
  long long int k;
  for (long long int l = 2; l <= n; l++) {
    for (long long int i = 0; i < n - l + 1; i++) {
      long long int j = i + l - 1;
      temp = s[j];
      dp[i][j] = dp[i][j - 1] + 1;
      for (k = j - 1; k >= i; k--) {
        if (s[k] == temp) {
          dp[i][j] = min(dp[i][k] + dp[k + 1][j - 1], dp[i][j]);
        }
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
