#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
const int LM = 500;
long long INF = 1e9;
string s;
int n, a[LM + 2], ans = INF;
int dp[LM + 2][LM + 2][28];
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  ;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 1; i <= n; i++) {
    a[i] = s[i - 1] - 'a' + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int x = 1; x <= 26; x++) {
      dp[i][i][x] = (a[i] == x ? 0 : INF);
    }
  }
  for (int l = n; l >= 1; l--) {
    for (int r = l + 1; r <= n; r++) {
      for (int x = 1; x <= 26; x++) {
        if (x == a[r]) {
          dp[l][r][x] = dp[l][r - 1][x];
        } else {
          int m = dp[l][r - 1][x] + 1;
          for (int j = l + 1; j <= r - 1; j++) {
            m = min(m, dp[j][r - 1][a[r]] + 1 + dp[l][j - 1][x]);
          }
          dp[l][r][x] = m;
        }
      }
    }
  }
  for (int i = 1; i <= 26; i++) {
    ans = min(ans, dp[1][n][i] + 1);
  }
  cout << ans << endl;
}
