Problem: You are given a string s of length n consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.

Calculate the minimum number of operations to delete the whole string s.

Input

The first line contains one integer n (1 ≤ n ≤ 500) — the length of string s.

The second line contains the string s (|s| = n) consisting of lowercase Latin letters.

Output

Output a single integer — the minimal number of operation to delete string s.

Examples

Input


5
abaca


Output


3

Input


8
abcddcba


Output


4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
long long int fexp(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % 1000000007;
    b /= 2;
    a = a * a % 1000000007;
  }
  return ans;
}
long long int inverse(long long int a, long long int p) {
  return fexp(a, p - 2);
}
void ingraph(vector<vector<long long int> >& graph, long long int m) {
  long long int x, y;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
}
long long int modify(long long int n) {
  long long int res = n;
  res %= 1000000007;
  res += 1000000007;
  res %= 1000000007;
  return res;
}
long long int ctoi(char x) { return (long long int)(x - 'a'); }
long long int dp[501][501];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    string str;
    cin >> str;
    vector<long long int> vec;
    vec.push_back(ctoi(str[0]));
    if (n > 1) {
      for (long long int i = 1; i < str.size(); i++) {
        if (str[i] == str[i - 1])
          continue;
        else
          vec.push_back(ctoi(str[i]));
      }
    }
    n = vec.size();
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < n; j++) {
        if (i == j)
          dp[i][j] = 1;
        else
          dp[i][j] = (long long int)1e18;
      }
    }
    if (n > 1) {
      for (long long int l = 2; l <= n; l++) {
        for (long long int i = 0; i < n - l + 1; i++) {
          long long int j = i + l - 1;
          if (vec[i] == vec[j]) {
            for (long long int k = i + 1; k < j; k++) {
              if (vec[i] == vec[k])
                dp[i][j] = min(dp[i][j], min(dp[i][k] + dp[k + 1][j] - 1,
                                             dp[i][k - 1] + dp[k][j] - 1));
              else
                dp[i][j] = min(dp[i][j], min(dp[i][k] + dp[k + 1][j] - 1,
                                             dp[i][k - 1] + dp[k][j] - 1));
            }
          } else {
            for (long long int k = i; k < j; k++) {
              dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
            }
          }
        }
      }
    }
    cout << dp[0][n - 1];
  }
}