#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  string st;
  cin >> n >> k >> st;
  vector<int> apos;
  vector<int> bpos;
  for (int i = 0; i < n; i++) {
    if (st[i] == 'a')
      apos.push_back(i);
    else
      bpos.push_back(i);
  }
  if (apos.size() == 0 || bpos.size() == 0) {
    cout << n;
    return 0;
  }
  if (apos.size() <= k || bpos.size() <= k) {
    cout << n;
    return 0;
  }
  int ans = 0;
  int s = 0;
  int i = 0;
  for (i; i + k < bpos.size(); i++) {
    ans = max(ans, bpos[i + k] - s);
    s = bpos[i] + 1;
  }
  ans = max(ans, n - s);
  i = 0;
  s = 0;
  for (i; i + k < apos.size(); i++) {
    ans = max(ans, apos[i + k] - s);
    s = apos[i] + 1;
  }
  ans = max(ans, n - s);
  cout << ans;
  return 0;
}
