#include <bits/stdc++.h>
using namespace std;
int n, m;
int calc(string s) {
  int ans_b = 0, j = -1, ans = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'b') ans_b++;
    while (j <= i && ans_b > m) {
      j++;
      if (s[j] == 'b') ans_b--;
    }
    ans = max(ans, i - j);
  }
  return ans;
}
int main() {
  cin >> n >> m;
  string s;
  cin >> s;
  int r = calc(s);
  for (int i = 0; i < s.length(); i++) s[i] = s[i] ^ 'a' ^ 'b';
  cout << max(r, calc(s)) << endl;
  return 0;
}
