use std::io::{stdin, BufRead, BufReader};
fn main() {
let mut stdin = BufReader::new(stdin());
let mut cur_line = String::new();
stdin.read_line(&mut cur_line).unwrap();
let mut nums = cur_line
.split_whitespace()
.map(|s| s.parse::<usize>().unwrap());
let n = nums.next().unwrap();
let k = nums.next().unwrap();
cur_line.clear();
stdin.read_line(&mut cur_line).unwrap();
let v = cur_line.trim().as_bytes();
let mut dp = vec![[[[0u16; 10]; 10]; 10]; n];
for a in 0..k {
for b in 0..k {
for c in 0..k {
if a + b + c < k {
match v.last().unwrap() {
b'A' => {
if a == 0 && b > 0 && c > 0 {
dp[v.len() - 1][a][b][c] = 1;
}
}
b'B' => {
if a > 0 && b == 0 && c > 0 {
dp[v.len() - 1][a][b][c] = 1;
}
}
b'C' => {
if a > 0 && b > 0 && c == 0 {
dp[v.len() - 1][a][b][c] = 1;
}
}
_ => (),
}
}
}
}
}
for i in (0..n - 1).rev() {
for a in 0..k {
for b in 0..k {
if a + b >= k {
break;
}
for c in 0..k {
if a + b + c >= k {
break;
}
match v[i] {
b'A' => {
if a == 0 && b > 0 && c > 0 {
dp[i][a][b][c] = 1 + dp[i + 1][a][b - 1][c - 1];
} else {
dp[i][a][b][c] = dp[i + 1][a + 1][b][c].max(dp[i + 1][a][b][c]);
}
}
b'B' => {
if a > 0 && b == 0 && c > 0 {
dp[i][a][b][c] = 1 + dp[i + 1][a - 1][b][c - 1];
} else {
dp[i][a][b][c] = dp[i + 1][a][b + 1][c].max(dp[i + 1][a][b][c]);
}
}
b'C' => {
if a > 0 && b > 0 && c == 0 {
dp[i][a][b][c] = 1 + dp[i + 1][a - 1][b - 1][c];
} else {
dp[i][a][b][c] = dp[i + 1][a][b][c + 1].max(dp[i + 1][a][b][c]);
}
}
_ => (),
}
}
}
}
}
println!("{}", dp[0][0][0][0]);
}