#include <bits/stdc++.h>
using namespace std;
int n, k, l = 0, r = 0, na = 0, nb = 0, resa = 0, resb = 0;
string s;
int main() {
  std::cin >> n >> k >> s;
  l = 0, r = 0;
  nb = (s[0] == 'b');
  resa = !nb;
  while (!k && nb) ++l, ++r, nb = (s[l] == 'b');
  while (r < n - 1) {
    if (s[r + 1] == 'a' || (s[r + 1] == 'b' && nb < k))
      nb += (s[r + 1] == 'b'), r++;
    else if (l == r && !(s[l + 1] == 'b' && nb < k) && s[l] == 'b')
      ++l, ++r;
    else
      nb -= (s[l] == 'b'), l++;
    resa = (((resa) > (r - l + 1)) ? (resa) : (r - l + 1));
  }
  l = 0, r = 0;
  na = (s[0] == 'a');
  resb = !na;
  while (!k && na) ++l, ++r, na = (s[l] == 'a');
  while (r < n - 1) {
    if (s[r + 1] == 'b' || (s[r + 1] == 'a' && na < k))
      na += (s[r + 1] == 'a'), r++;
    else if (l == r && !(s[l + 1] == 'a' && na < k) && s[l] == 'a')
      ++l, ++r;
    else
      na -= (s[l] == 'a'), l++;
    resb = (((resb) > (r - l + 1)) ? (resb) : (r - l + 1));
  }
  std::cout << (((resa) > (resb)) ? (resa) : (resb)) << '\n';
}
