#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long inf = 1LL << 30;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int N = 505;
int mem[N][N];
char a[N];
int dp(int l, int r) {
  if (l == r) return 1;
  if (l > r) return 0;
  int &ret = mem[l][r];
  if (ret != -1) return ret;
  ret = 1 + dp(l + 1, r);
  for (int i = l + 1; i <= r; i++)
    if (a[i] == a[l]) ret = min(ret, dp(l + 1, i - 1) + dp(i, r));
  return ret;
}
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", &a);
  memset(mem, -1, sizeof mem);
  printf("%d\n", dp(0, n - 1));
}
