#include <bits/stdc++.h>
char arr[110000];
int solve_a(int len, int k) {
  int L = 0;
  int R = 0;
  int max = 0;
  int temp = k;
  while (R < len) {
    if (arr[R] == 'b') temp--;
    while (temp == -1) {
      if (arr[L] == 'b') temp++;
      L++;
    }
    R++;
    if (R - L > max) max = (R - L);
  }
  return max;
}
int solve_b(int len, int k) {
  int L = 0;
  int R = 0;
  int max = 0;
  int temp = k;
  while (R < len) {
    if (arr[R] == 'a') temp--;
    while (temp == -1) {
      if (arr[L] == 'a') temp++;
      L++;
    }
    R++;
    if (R - L > max) max = (R - L);
  }
  return max;
}
int main() {
  int a, b, c, d, e, f;
  scanf("%d%d", &a, &b);
  getchar();
  gets(arr);
  int res = solve_a(a, b);
  int res1 = solve_b(a, b);
  res > res1 ? printf("%d", res) : printf("%d", res1);
}
