#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void print1(T... t) {
  ((cout << t << " "), ...);
}
template <typename... T>
void print2(T... t) {
  vector<vector<long long>> ans = {t...};
  for (long long i = 0; i < (long long)ans.size(); i++) {
    if (i != 0)
      cout << "\t\t";
    else
      cout << "\t";
    for (long long j = 0; j < (long long)ans[i].size(); j++) {
      cout << ans[i][j] << " ";
    }
    if (i != (long long)ans.size() - 1) cout << endl;
  }
}
template <typename T>
void printV(T vec) {
  for (int i = 0; i < (long long)vec.size(); i++)
    cout << vec[i] << " " << flush;
  cout << endl;
}
const int INF = 1e9 + 5;
template <typename T>
void itR(T map) {
  for (auto itr = map.begin(); itr != map.end(); itr++) {
    cout << " [ "
            "itr->first, itr->second"
         << " : ";
    print1(itr->first, itr->second);
    cout << "]" << endl;
    ;
  }
  cout << endl;
}
long long solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long dp[s.size()][s.size()];
  for (int i = 0; i < (long long)n; i++) {
    for (int j = 0; j < (long long)n; j++) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i < (long long)s.size(); i++) {
    dp[i][i] = 1;
  }
  for (int size = 1; size < (long long)s.size(); size++) {
    for (int l = 0; l < (long long)s.size(); l++) {
      long long r = size + l;
      if (r >= (long long)s.size()) continue;
      long long a = INF;
      for (int i = l + 1; i <= r; i++) {
        if (s[l] == s[i])
          a = min(a, ((i - 1 < l + 1) ? 0 : dp[l + 1][i - 1]) + dp[i][r]);
      }
      dp[l][r] = min(a, 1 + dp[l + 1][r]);
    }
  }
  return dp[0][s.size() - 1];
}
int main() {
  cout << setprecision(10);
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long ans = solve();
  cout << ans << endl;
  return 0;
}
