#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <typename Type>
string ToString(const Type& val) {
  stringstream ss;
  ss << val;
  return ss.str();
}
long long __gcd(long long a, long long b) {
  while (a != 0) {
    long long __t = b % a;
    b = a;
    a = __t;
  }
  return b;
}
inline long long absl(long long x) { return (x < 0 ? -x : x); }
inline long long sqr(long long x) { return x * x; }
long long ModPower(long long x, long long st, long long mod) {
  if (!st) return 1;
  if (st & 1) return (x % mod) * ModPower(x, st - 1, mod) % mod;
  return sqr(ModPower(x, st >> 1, mod)) % mod;
}
long long fact(unsigned x) {
  long long res = 1;
  for (; x > 0; x--) res *= x;
  return res;
}
long long __lcm(long long a, long long b, long long gcd = 0) {
  if (!gcd) gcd = __gcd(a, b);
  return (a / gcd) * b;
}
vector<long long> sumArr;
long long getSum(unsigned l, unsigned r) {
  return (l ? sumArr[r] - sumArr[l - 1] : sumArr[r]);
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  ios_base::sync_with_stdio(false);
  unsigned N;
  cin >> N;
  string s;
  cin >> s;
  vector<vector<long long> > d(N, vector<long long>(N));
  for (unsigned i = 0; i < N; i++) d[i][i] = 1;
  for (unsigned k = 2; k <= N; k++) {
    for (unsigned i = 0; i <= N - k; i++) {
      unsigned j = i + k - 1;
      d[i][j] = d[i + 1][j] + (s[i] != s[j]);
      for (int h = i + 1; h <= (int)j; h++) {
        if (s[h] == s[i]) d[i][j] = min(d[i][j], d[i + 1][h - 1] + d[h][j]);
      }
    }
  }
  cout << d[0].back();
  return 0;
}
