#include <bits/stdc++.h>
using namespace std;
int pref[100005][2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  string s;
  cin >> n >> k >> s;
  for (int i = 0; i < n; i++) {
    pref[i + 1][0] = pref[i][0] + (s[i] == 'a');
    pref[i + 1][1] = pref[i][1] + (s[i] == 'b');
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int ki = i, ka = n, res = -1;
    while (ki <= ka) {
      int mid = (ki + ka) / 2;
      if (pref[mid][0] - pref[i - 1][0] <= k) {
        res = mid;
        ki = mid + 1;
      } else
        ka = mid - 1;
    }
    if (res != -1) ans = max(ans, res - i + 1);
    ki = i;
    ka = n;
    res = -1;
    while (ki <= ka) {
      int mid = (ki + ka) / 2;
      if (pref[mid][1] - pref[i - 1][1] <= k) {
        res = mid;
        ki = mid + 1;
      } else
        ka = mid - 1;
    }
    if (res != -1) ans = max(ans, res - i + 1);
  }
  cout << ans << '\n';
  return 0;
}
