#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
int getAns(string s, char x) {
  int ans = -1;
  int j = 0;
  int c = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != x) ++c;
    while (j <= i && c > k) {
      if (s[j++] != x) --c;
    }
    if (i - j + 1 > ans) ans = i - j + 1;
  }
  return ans;
}
int main() {
  cin >> n >> k;
  cin >> s;
  int res1 = getAns(s, 'a');
  int res2 = getAns(s, 'b');
  int res3 = max(res1, res2);
  cout << res3;
  return 0;
}
