#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, j, i, l, r, ans = 0, x, y, minimum;
  scanf("%d", &n);
  scanf("%d", &k);
  int count_a[n], count_b[n];
  char str[n + 1], ch;
  scanf("%s", str);
  for (i = 0; i < n; i++) {
    count_a[i] = 0;
    count_b[i] = 0;
  }
  for (i = 0; i < n; i++) {
    if (str[i] == 'a') count_a[i]++;
    if (str[i] == 'b') count_b[i]++;
  }
  for (i = 1; i < n; i++) {
    count_a[i] += count_a[i - 1];
    count_b[i] += count_b[i - 1];
  }
  l = 0;
  r = 0;
  while (r < n) {
    if (l == 0) {
      x = count_a[r];
      y = count_b[r];
    } else {
      x = count_a[r] - count_a[l - 1];
      y = count_b[r] - count_b[l - 1];
    }
    minimum = min(x, y);
    if (k >= minimum) {
      ans = max(ans, r - l + 1);
      r++;
    } else
      l++;
  }
  cout << ans << endl;
  return 0;
}
