#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
int solve(string s, char x) {
  int ans = 0, j = 0, cont = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != x) cont++;
    while (cont > k) {
      if (s[j++] != x) cont--;
    }
    if (i - j + 1 > ans) ans = i - j + 1;
  }
  return ans;
}
int main(int argc, char const *argv[]) {
  cin >> n >> k >> s;
  int resp1 = solve(s, 'a');
  int resp2 = solve(s, 'b');
  int resp3 = max(resp1, resp2);
  cout << resp3 << endl;
  return 0;
}
