#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int t[3][2][51][51];
int &state(int i, int a, int b, int c) {
if (!a) return t[0][i % 2][b][c];
if (!b) return t[1][i % 2][a][c];
return t[2][i % 2][a][b];
}
const int INF = 1e9;
void cmax(int &x, int y) {
x = max(x, y);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
if (k < 3) {
cout << 0 << endl;
} else {
string s;
cin >> s;
for (int a = 0; a <= k; ++a) {
for (int b = 0; b <= k; ++b) {
t[0][0][a][b] = -INF;
t[1][0][a][b] = -INF;
t[2][0][a][b] = -INF;
t[0][1][a][b] = -INF;
t[1][1][a][b] = -INF;
t[2][1][a][b] = -INF;
}
}
int ans = 0;
t[0][0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int a = 0; a <= k; ++a) {
for (int b = 0; b <= k - a; ++b) {
t[0][i % 2][a][b] = t[0][(i + 1) % 2][a][b];
t[1][i % 2][a][b] = t[1][(i + 1) % 2][a][b];
t[2][i % 2][a][b] = t[2][(i + 1) % 2][a][b];
}
}
if (s[i - 1] == 'A') {
for (int a = 0; a <= 0; ++a) {
for (int b = 1; b < k; ++b) {
for (int c = 1; c < k - b; ++c) {
cmax(state(i, a, b - 1, c - 1), state(i - 1, a, b, c) + 1);
}
}
}
for (int a = 0; a < k; ++a) {
for (int b = 0; b < k - a; ++b) {
for (int c = 0; c < k - a - b; ++c) {
if (b && c) break;
cmax(state(i, a + 1, b, c), state(i - 1, a, b, c));
}
}
}
} else if (s[i - 1] == 'B') {
for (int a = 1; a < k; ++a) {
for (int b = 0; b <= 0; ++b) {
for (int c = 1; c < k - a; ++c) {
cmax(state(i, a - 1, b, c - 1), state(i - 1, a, b, c) + 1);
}
}
}
for (int a = 0; a < k; ++a) {
for (int b = 0; b < k - a; ++b) {
for (int c = 0; c < k - a - b; ++c) {
if (a && c) break;
cmax(state(i, a, b + 1, c), state(i - 1, a, b, c));
}
}
}
} else {
for (int a = 1; a < k; ++a) {
for (int b = 1; b < k - a; ++b) {
for (int c = 0; c <= 0; ++c) {
cmax(state(i, a - 1, b - 1, c), state(i - 1, a, b, c) + 1);
}
}
}
for (int a = 0; a < k; ++a) {
for (int b = 0; b < k - a; ++b) {
for (int c = 0; c < k - a - b; ++c) {
if (a && b) break;
cmax(state(i, a, b, c + 1), state(i - 1, a, b, c));
}
}
}
}
for (int a = 0; a <= k; ++a) {
for (int b = 0; b <= k - a; ++b) {
for (int c = 0; c <= k - a - b; ++c) {
if (a && b && c) break;
cmax(ans, state(i, a, b, c));
}
}
}
}
cout << ans << endl;
}
}