#include <bits/stdc++.h>
using namespace std;
char arr[100010];
int findas(char arr[], int n, int m) {
  int wL = 0, wR = 0;
  int bestL = 0, bestWindow = 0;
  int aCount = 0;
  while (wR < n) {
    if (aCount <= m) {
      if (arr[wR] == 'a') aCount++;
      wR++;
    }
    if (aCount > m) {
      if (arr[wL] == 'a') aCount--;
      wL++;
    }
    if (wR - wL > bestWindow) {
      bestWindow = wR - wL;
      bestL = wL;
    }
  }
  return bestWindow;
}
int findbs(char arr[], int n, int m) {
  int wL = 0, wR = 0;
  int bestL = 0, bestWindow = 0;
  int bCount = 0;
  while (wR < n) {
    if (bCount <= m) {
      if (arr[wR] == 'b') bCount++;
      wR++;
    }
    if (bCount > m) {
      if (arr[wL] == 'b') bCount--;
      wL++;
    }
    if (wR - wL > bestWindow) {
      bestWindow = wR - wL;
      bestL = wL;
    }
  }
  return bestWindow;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  scanf("%s", arr);
  int aconstant = findas(arr, n, k);
  int bconstant = findbs(arr, n, k);
  if (aconstant >= bconstant)
    printf("%d\n", aconstant);
  else
    printf("%d\n", bconstant);
  return 0;
}
