#include <bits/stdc++.h>
std::string s;
int32_t n, k;
int main() {
  std::cin >> n >> k;
  std::cin >> s;
  int32_t st = 0, cnt = 0, maxim = 0;
  for (int dr = 0; dr < n; dr++) {
    if (s[dr] == 'b') cnt++;
    if (cnt <= k) maxim = std::max(maxim, dr - st + 1);
    while (cnt > k) {
      if (s[st] == 'b') cnt--;
      st++;
    }
  }
  st = 0;
  cnt = 0;
  for (int dr = 0; dr < n; dr++) {
    if (s[dr] == 'a') cnt++;
    if (cnt <= k) maxim = std::max(maxim, dr - st + 1);
    while (cnt > k) {
      if (s[st] == 'a') cnt--;
      st++;
    }
  }
  std::cout << maxim;
}
