#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
void write(int x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar((x % 10) ^ 48);
}
const int mod = 1e9 + 7;
const int N = 5e2 + 5;
const int INF = 0x3f3f3f3f;
int f[N][N], n;
char s[N];
signed main() {
  n = read();
  for (int i = 0; i < n; i++) s[i] = getchar();
  for (int len = 0; len < n; len++) {
    for (int i = 0; i < n - len + 1; i++) {
      int j = i + len;
      int minn = INF;
      if (i == j) {
        f[i][j] = 1;
        continue;
      }
      for (int k = i; k < j; k++) {
        if (s[j] == s[k])
          minn = min(minn, f[i][k] + f[k + 1][j - 1]);
        else
          minn = min(minn, f[i][k] + f[k + 1][j - 1] + 1);
      }
      f[i][j] = minn;
    }
  }
  write(f[0][n - 1]);
  putchar('\n');
  return 0;
}
