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