#include <bits/stdc++.h>
static void print_int(int64_t n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  if (n == 0) {
    putchar('0');
    return;
  }
  int s[20], len = 0;
  while (n > 0) {
    s[len++] = n % 10 + '0';
    n /= 10;
  }
  while (len > 0) {
    putchar(s[--len]);
  }
}
static int64_t read_int(void) {
  int prev = '\0';
  int c = getchar();
  while (!('0' <= c && c <= '9')) {
    prev = c;
    c = getchar();
  }
  int64_t res = 0;
  while ('0' <= c && c <= '9') {
    res = 10 * res + c - '0';
    c = getchar();
  }
  return prev == '-' ? -res : res;
}
void run(void) {
  int32_t n = read_int();
  char *s = (char *)calloc(n + 1, sizeof(char));
  scanf("%s", s);
  int32_t *dp = (int32_t *)calloc((n + 1) * (n + 1), sizeof(int32_t));
  for (int32_t len = 1; len <= n; ++len) {
    for (int32_t l = 0; l + len <= n; ++l) {
      int32_t r = l + len;
      int32_t min = 1 + dp[((l + 1) * (n + 1) + (r))];
      for (int32_t i = l + 1; i < r; ++i) {
        if (s[l] != s[i]) continue;
        int32_t d = dp[((l + 1) * (n + 1) + (i))] + dp[((i) * (n + 1) + (r))];
        min = min > d ? d : min;
      }
      dp[((l) * (n + 1) + (r))] = min;
    }
  }
  print_int(dp[((0) * (n + 1) + (n))]);
  puts("");
}
int main(void) {
  run();
  return 0;
}
