#include <bits/stdc++.h>
using namespace std;
int res;
int del;
int a, b;
int N, K;
string text;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> K;
  cin >> text;
  for (int i = 0; i < text.size(); i++) {
    a += text[i] == 'a';
    b += text[i] == 'b';
    if (min(a, b) <= K)
      res = max(res, a + b);
    else
      text[del++] == 'a' ? a-- : b--;
  }
  cout << res << endl;
}
