#include <bits/stdc++.h>
using namespace std;
const int MAXINT = (int)2e5 + 10;
int p1[MAXINT], p2[MAXINT];
char c[MAXINT];
void fast() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
int main() {
  fast();
  int n, k, a = 0, b = 0, ans = 0;
  cin >> n >> k;
  string s;
  cin >> s;
  int l = 0, r = 0;
  while (r < n) {
    if (s[r] == 'b') b++;
    if (b <= k) ans = max(ans, r - l + 1);
    while (b > k) {
      if (s[l] == 'b') b--;
      l++;
    }
    r++;
  }
  l = 0;
  r = 0;
  while (r < n) {
    if (s[r] == 'a') a++;
    if (a <= k) ans = max(ans, r - l + 1);
    while (a > k) {
      if (s[l] == 'a') a--;
      l++;
    }
    r++;
  }
  cout << ans;
  return 0;
}
