#include <bits/stdc++.h>
using namespace std;
bool check(long long int mid, string &s, long long int &k) {
  long long int ca = 0, cb = 0;
  for (long long int i = 0; i < mid; i++) {
    if (s[i] == 'a')
      ca++;
    else
      cb++;
  }
  if (min(ca, cb) <= k) return true;
  for (long long int i = 1; i <= s.length() - mid; i++) {
    if (s[i - 1] == 'a')
      ca--;
    else
      cb--;
    if (s[i + mid - 1] == 'a')
      ca++;
    else
      cb++;
    if (min(ca, cb) <= k) return true;
  }
  return false;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long int l = 1, r = n, mid;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (check(mid, s, k))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << l - 1 << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
}
