#include <stdio.h>
#include <stdlib.h>

int windowSolve(char* str, int oper, int len) {
  int res = -2147483648; //MIN
  int left = 0, right = 0;
  int an = 0, bn = 0;

  while (right < len) {
    if (*(str + right) == 'a') {
      an++;
    } else {
      bn++;
    }
    if (an <= oper || bn <= oper) {
      right++;
    } else {
      res = (res > right - left) ? res : right - left;

      if (*(str + left) == 'a') {
        left++;
        an--;
      } else {
        left++;
        bn--;
      }
      right++;
    }
  }

  res = (res > right - left) ? res : right - left;
  return res;
}

int main() {
  int len, oper;
  scanf("%d %d", &len, &oper);
  char* str = (char*)malloc((len + 1) * sizeof(char));
  scanf("%s", str);
  printf("%d\n", windowSolve(str, oper, len));
  free(str);
  return 0;
}