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