#include <bits/stdc++.h>
using namespace std;
int subSearch(string st, int k, int mid) {
  int count[] = {0, 0};
  for (int i = 0; i < mid; i++) count[st[i] - 'a']++;
  if (k >= min(count[0], count[1])) return 1;
  for (int i = 0; i + mid < st.size(); i++) {
    count[st[i] - 'a']--;
    count[st[i + mid] - 'a']++;
    if (k >= min(count[0], count[1])) return 1;
  }
  return 0;
}
int main() {
  int n, k;
  cin >> n >> k;
  string st;
  cin >> st;
  int l = 1, r = n;
  int ans = 0;
  while (l <= r) {
    int mid = l + r >> 1;
    if (subSearch(st, k, mid)) {
      ans = max(ans, mid);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans;
}
