#include <bits/stdc++.h>
using namespace std;
string s;
int n, k;
int next_cons(char c, int index) {
  if (c == s[index]) return index;
  for (int i = index + 1; i < n; i++) {
    if (s[i] == c) return i;
  }
  return -1;
}
int main() {
  scanf("%d%d", &n, &k);
  cin >> s;
  int len = s.length();
  int low = 0, high = 0;
  int mx = INT_MIN;
  low = high = 0;
  int kk = k;
  while (high < n) {
    if (s[high] == 'a')
      high++;
    else if (k > 0) {
      high++;
      k--;
    } else {
      mx = max(mx, high - low);
      low = next_cons('b', low) + 1;
      high++;
    }
  }
  if (s[n - 1] == 'a' || k > 0) mx = max(mx, high - low);
  if (mx == INT_MIN) mx = n;
  low = high = 0;
  while (high < n) {
    if (s[high] == 'b')
      high++;
    else if (kk > 0) {
      high++;
      kk--;
    } else {
      mx = max(mx, high - low);
      low = next_cons('a', low) + 1;
      high++;
    }
  }
  if (s[n - 1] == 'b' || kk > 0) mx = max(mx, high - low);
  if (mx == INT_MIN) mx = n;
  printf("%d\n", mx);
  return 0;
}
