#include <bits/stdc++.h>
using namespace std;
int dp[600][600], a;
string st;
int solve(int s, int sz) {
  if (s >= a || sz <= 0 || s + sz > a) return 0;
  if (sz == 1) return 1;
  if (dp[s][sz] != 0) return dp[s][sz];
  dp[s][sz - 1] = solve(s, sz - 1);
  dp[s + 1][sz - 1] = solve(s + 1, sz - 1);
  dp[s][sz] = 1 + dp[s + 1][sz - 1];
  int numP = 1, numN = sz - 1;
  for (int i = s + 1; i < s + sz; ++i) {
    if (st[i] == st[s]) {
      dp[s][sz] = min(dp[s][sz], dp[s + 1][numP - 1] + dp[i][numN]);
    }
    numP++;
    numN--;
  }
  return dp[s][sz];
}
int main() {
  cin >> a >> st;
  cout << solve(0, a) << endl;
  return 0;
}
