#include <bits/stdc++.h>
using namespace std;
char s[int(1e5 + 50)];
int main() {
  int n, m, suma, sumb;
  while (~scanf("%d%d", &n, &m)) {
    suma = sumb = 0;
    scanf("%s", s);
    int cnt = 0, L = 0, R = 0;
    int max1 = 0;
    while (1) {
      while (cnt < n && min(suma, sumb) <= m) {
        if (s[cnt] == 'a') suma++;
        if (s[cnt] == 'b') sumb++;
        R = ++cnt;
      }
      if (min(suma, sumb) <= m) break;
      max1 = max(max1, R - L - 1);
      while (min(suma, sumb) > m) {
        if (s[L] == 'a') suma--;
        if (s[L] == 'b') sumb--;
        L++;
      }
    }
    max1 = max(max1, R - L);
    printf("%d\n", max1);
  }
  return 0;
}
