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