#include <bits/stdc++.h>
using namespace std;
int n, f[505][505];
string s;
void solve() {
  cin >> n >> s;
  string res = "";
  res += s[0];
  for (int i = 1; i < n; i++)
    if (s[i] != s[i - 1]) res += s[i];
  for (int i = 0; i < n; i++) f[i][i] = 1;
  for (int j = 0; j < n; j++)
    for (int i = 0; i < n; i++)
      if (i < j) {
        int res = 1e9;
        for (int k = j - 1; k >= i; k--)
          if (s[k] == s[j]) res = min(res, f[i][k] + f[k + 1][j - 1]);
        f[i][j] = min(f[i][j - 1] + 1, res);
      }
  cout << f[0][n - 1] << endl;
}
int main() {
  solve();
  return 0;
}
