#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int dp[510][510];
int main() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; ++i) dp[i][i] = 1;
  for (int i = n - 2; i >= 0; --i) {
    for (int j = i + 1; j < n; ++j) {
      dp[i][j] = dp[i + 1][j] + 1;
      for (int k = i + 1; k <= j; ++k) {
        if (s[i] == s[k]) dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k][j]);
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}
