#include <bits/stdc++.h>
using namespace std;
int n, k;
string a;
int change(char c) {
  int j = 0, i = 0, ans = 0, cont = 0;
  for (i = 0; i < n; i++) {
    if (a[i] == c) cont++;
    if (cont > k) {
      while (cont > k)
        if (a[j++] == c) cont--;
    }
    ans = max(ans, i - j + 1);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  while (cin >> n >> k) {
    a = "";
    int suma = 0, sumb = 0;
    for (int i = 0; i < n; ++i) {
      char c;
      cin >> c;
      if (c == 'a')
        suma++;
      else
        sumb++;
      a += c;
    }
    int ans;
    if (suma > sumb)
      ans = change('b');
    else if (sumb > suma)
      ans = change('a');
    else
      ans = max(change('a'), change('b'));
    cout << ans << endl;
  }
  return 0;
}
