#include <bits/stdc++.h>
using namespace std;
int dp[505][505];
set<int> a[28];
string s;
int func(int i, int j) {
  int d = INT_MAX, k;
  if (i > j) return 0;
  if (i == j - 1 || i == j) {
    if (s[i] == s[j])
      return 1;
    else
      return 2;
  }
  if (dp[i][j] != -1) return dp[i][j];
  set<int>::iterator it;
  it = a[s[i] - 97].upper_bound(i);
  if (it == a[s[i] - 97].end() || ((it != a[s[i] - 97].end()) && ((*it) > j))) {
    dp[i][j] = func(i + 1, j) + 1;
    return dp[i][j];
  }
  k = (*it);
  while (k <= j) {
    d = min(func(i + 1, k - 1) + func(k, j), d);
    it = a[s[i] - 97].upper_bound(k);
    if (it == a[s[i] - 97].end()) break;
    k = (*it);
  }
  dp[i][j] = min(d, func(i + 1, j) + 1);
  return dp[i][j];
}
int main() {
  int n, i;
  cin >> n >> s;
  for (i = 0; i < n; i++) a[s[i] - 97].insert(i);
  memset(dp, -1, sizeof(dp));
  cout << func(0, n - 1) << endl;
}
