#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long i = 0, j = 0, countFirst = 0, K = k, maxFirst = INT_MIN;
  char first = s[0], second = first == 'a' ? 'b' : 'a';
  while (j < s.size()) {
    if (first != s[j]) --K;
    if (K >= 0) ++countFirst;
    maxFirst = max(maxFirst, countFirst);
    while (K < 0 && i < s.size()) {
      if (s[i] == second) ++K;
      ++i;
      if (K < 0) --countFirst;
    }
    ++j;
  }
  long long countS = 0, maxSec = INT_MIN;
  i = 0, j = 0, K = k;
  while (j < s.size()) {
    if (second != s[j]) --K;
    if (K >= 0) ++countS;
    maxSec = max(maxSec, countS);
    while (K < 0 && i < s.size()) {
      if (s[i] == first) ++K;
      ++i;
      if (K < 0) --countS;
    }
    ++j;
  }
  maxFirst = max(maxFirst, maxSec);
  cout << maxFirst << endl;
}
