#include <bits/stdc++.h>
int ans(std::string arr, int n, int k, char c) {
  int wl = 0, wr = 0;
  int bestl = 0, bestwindow = 0;
  int cnt = 0;
  while (wr < n) {
    if (cnt <= k) {
      if (arr[wr] == c) {
        ++cnt;
      }
      wr++;
    }
    if (cnt > k) {
      if (arr[wl] == c) --cnt;
      wl++;
    }
    if (wr - wl > bestwindow) {
      bestwindow = wr - wl;
    }
  }
  return bestwindow;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, k;
  std::cin >> n >> k;
  std::string s;
  std::cin >> s;
  std::cout << std::max(ans(s, n, k, 'a'), ans(s, n, k, 'b')) << std::endl;
  return 0;
}
