#include <bits/stdc++.h>
using namespace std;
const int N = 103;
const int INF = 0x3f3f3f3f;
int n;
string s;
int dp[N][N][130];
int sum[N][N];
bool used[N][N][130];
int fun(char c) { return c - 'a' + 1; }
int ans;
int calc(int l, int r, char ch) {
  if (used[l][r][ch]) {
    return dp[l][r][ch];
  }
  used[l][r][ch] = 1;
  if (l == r) {
    dp[l][r][s[l]] = 0;
    sum[l][r] = 0;
    return dp[l][r][s[l]];
  }
  for (char c = 'a'; c <= 'z'; c++) {
    calc(l + 1, r, c);
    calc(l, r - 1, c);
  }
  for (int mid = l; mid < r; mid++) {
    for (char c = 'a'; c <= 'z'; c++) {
      char prev31231231;
      if (c > 'a') {
        prev31231231 = c - 1;
        int &res = dp[l][r][prev31231231];
        res = max(res, dp[l][mid][c] + dp[mid + 1][r][prev31231231] + 1);
        res = max(res, dp[l][mid][prev31231231] + dp[mid + 1][r][c] + 1);
      }
    }
  }
  for (char c = 'a'; c <= 'z'; c++) {
    sum[l][r] = max(sum[l][r], dp[l][r][c]);
  }
  for (int mid = l; mid < r; mid++) {
    sum[l][r] = max(sum[l][r], sum[l][mid] + sum[mid + 1][r]);
  }
  ans = max(ans, sum[l][r]);
  return dp[l][r][ch];
}
inline void solve() {
  memset(dp, -INF, sizeof dp);
  memset(sum, -INF, sizeof sum);
  cin >> n >> s;
  s = ' ' + s;
  for (char c = 'a'; c <= 'z'; c++) {
    calc(1, n, c);
  }
  cout << ans;
}
int main() {
  int tests = 1;
  while (tests--) {
    solve();
  }
}
