#include <bits/stdc++.h>
using namespace std;
vector<long long> vec(30);
long long memo[500][500];
long long n;
string s, sUniq = "";
string removeDuplicatesFromString(string str) {
  int counter = 0;
  int i = 0;
  int size = str.size();
  int x;
  int length = 0;
  while (i < size) {
    x = str[i] - 97;
    if ((counter & (1 << x)) == 0) {
      str[length] = 'a' + x;
      counter = counter | (1 << x);
      length++;
    }
    i++;
  }
  return str.substr(0, length);
}
long long DP(long long i, long long j) {
  long long temp = 10000000005;
  if (i == j) {
    return 1;
  } else if (memo[i][j] != -1) {
    return memo[i][j];
  } else {
    for (long long k = i + 1; k <= j; k++) {
      if (sUniq[k] == sUniq[i]) {
        temp = min(temp, DP(i + 1, k - 1) + DP(k, j));
      }
    }
    return memo[i][j] = min(temp, 1 + DP(i + 1, j));
  }
}
int main() {
  memset(memo, -1, sizeof(memo));
  cin >> n >> s;
  sUniq = s[0];
  for (long long i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) sUniq += s[i];
  }
  cout << DP(0, sUniq.size() - 1);
  return 0;
}
