#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int a = 0, b = 0, del = 0, ans = 0;
  for (int i = 0; i < s.length(); i++) {
    s[i] == 'a' ? a++ : b++;
    if (min(a, b) <= k) {
      ans = max(ans, a + b);
    } else {
      s[del++] == 'a' ? a-- : b--;
    }
  }
  cout << ans << endl;
  return 0;
}
