#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 542;
int n;
string s;
int dp[N][N];
int go(int l, int r) {
  int &ans = dp[l][r];
  if (ans != -1) return ans;
  if (l > r) return ans = 0;
  if (l == r) return ans = 1;
  ans = 1 + go(l + 1, r);
  for (int i = l + 1; i <= r; i++)
    if (s[l] == s[i]) ans = min(ans, go(l + 1, i - 1) + go(i, r));
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  memset(dp, -1, sizeof(dp));
  cout << go(0, n - 1);
  return 0;
}
