#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int K = 10;
int dp[N+1][K+1][K+1][K+1];
// dp[i][A][B][C}]
int main(){
memset(dp, -1, sizeof(dp));
for(int i = 0; i <= N; ++i){
dp[i][0][0][0] = 0;
}
int n, k;
cin >> n >> k;
string s;
cin >> s;
s = "#" + s;
for(int i = 1; i <= n; ++i){
int x = (s[i] == 'B') + 2 * (s[i] == 'C');
for(int a = 0; a <= k; ++a){
for(int b = 0; b <= k; ++b){
for(int c = 0; c <= k; ++c){
if(dp[i-1][a][b][c] == -1)continue;
// cout << dp[i-1][a][b][c] << "\n";
if(x == 0){
// A
if(b&&c){
dp[i][a][b-1][c-1] = dp[i-1][a][b][c] + 1;
}
else dp[i][min(a+1, k)][b][c] = dp[i-1][a][b][c];
}
if(x == 1){
// B
if(a&&c){
dp[i][a-1][b][c-1] = dp[i-1][a][b][c] + 1;
}
else dp[i][a][min(b+1, k)][c] = dp[i-1][a][b][c];
}
if(x == 2){
// C
if(a&&n){
dp[i][a-1][b-1][c] = dp[i-1][a][b][c] + 1;
}
else dp[i][a][b][min(c+1, k)] = dp[i-1][a][b][c];
}
}
}
}
}
int ans = 0;
for(int a = 0; a <= k; ++a)
for(int b = 0; b <= k; ++b)
for(int c = 0; c <= k; ++c)
ans = max(ans, dp[n][a][b][c]);
cout << ans << "\n";
}