#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, k;
char s[N];
int main() {
  ios_base::sync_with_stdio(0);
  clock_t _ = clock();
  while (scanf("%d%d%s", &n, &k, s + 1) == 3) {
    int a, b, ans = 0;
    a = b = 0;
    for (int l = 1, r = 1; l <= n; ++l) {
      while (r <= n && b + (s[r] == 'b') <= k) b += (s[r++] == 'b');
      ans = max(ans, r - l);
      b -= s[l] == 'b';
    }
    for (int l = 1, r = 1; l <= n; ++l) {
      while (r <= n && a + (s[r] == 'a') <= k) a += (s[r++] == 'a');
      ans = max(ans, r - l);
      a -= s[l] == 'a';
    }
    printf("%d\n", ans);
  }
  return 0;
}
