#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long int inf = 1e18, M = 1e9 + 7;
const long long int N = 5e2 + 5, NN = 26;
long long int dp[N][N];
vector<long long int> arr[NN];
long long int sz[NN];
long long int n;
string s;
long long int rec(long long int l, long long int r) {
  if (l > r) return 0;
  if (l == r) return 1;
  long long int& res = dp[l][r];
  if (res != -1) return res;
  res = rec(l, r - 1) + 1;
  long long int x = s[r] - 'a', cur;
  for (long long int i = sz[x] - 1; i >= 0; --i) {
    cur = arr[x][i];
    if (l <= cur && cur < r) res = min(res, rec(l, cur) + rec(cur + 1, r - 1));
  }
  return res;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  for (long long int i = 0; i < n; ++i) arr[s[i] - 'a'].push_back(i);
  for (long long int i = 0; i < 26; ++i) sz[i] = arr[i].size();
  long long int ans = rec(0, n - 1);
  cout << ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
