#include <bits/stdc++.h>
using namespace std;
using ll = long long;
char str[505];
int memo[505][505];
int dp(int l, int r) {
  if (l >= r) return 0;
  if (memo[l][r]) return memo[l][r];
  int ptr = l;
  while (ptr < r && str[l] == str[ptr]) ptr++;
  int ret = 1 + dp(ptr, r);
  for (int i = ptr; i < r; ++i) {
    if (str[l] == str[i]) {
      ret = min(ret, dp(ptr, i) + dp(i, r));
    }
  }
  return memo[l][r] = ret;
}
int main() {
  int n;
  cin >> n >> str;
  cout << dp(0, n) << '\n';
}
