#include <bits/stdc++.h>
using std::max;
const int MAX_N = (int)1e5 + 10;
char str[MAX_N];
int a[MAX_N], b[MAX_N];
void solve() {
  int n, k;
  while (scanf("%d %d", &n, &k) == 2) {
    scanf("%s", str);
    int cnt_a, cnt_b, left, ans;
    cnt_a = cnt_b = left = ans = 0;
    a[0] = b[0] = -1;
    for (int i = 0; i < n; ++i) {
      if (str[i] == 'a') {
        a[++cnt_a] = i;
      } else {
        b[++cnt_b] = i;
      }
    }
    if (cnt_a <= k || cnt_b <= k) {
      printf("%d\n", n);
      continue;
    }
    a[++cnt_a] = b[++cnt_b] = n;
    while (left < cnt_a - k) {
      ans = max(ans, a[left + k + 1] - a[left] - 1);
      ++left;
    }
    left = 0;
    while (left < cnt_b - k) {
      ans = max(ans, b[left + k + 1] - b[left] - 1);
      ++left;
    }
    printf("%d\n", ans);
  }
}
int main() {
  solve();
  return 0;
}
