#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int dq[N];
int n, k, ck, j, st, dr = -1, len, ans;
char s[N];
int main() {
  cin >> n >> k >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'b') {
      ck++;
    }
    dq[++dr] = i;
    while (ck > k && st <= dr) {
      if (s[dq[st]] == 'b') {
        ck--;
      }
      if (dq[st] == j) {
        st++;
      }
      j++;
    }
    len = i - j + 1;
    ans = max(ans, len);
  }
  j = ck = st = 0;
  dr = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a') {
      ck++;
    }
    dq[++dr] = i;
    while (ck > k && st <= dr) {
      if (s[dq[st]] == 'a') {
        ck--;
      }
      if (dq[st] == j) {
        st++;
      }
      j++;
    }
    len = i - j + 1;
    ans = max(ans, len);
  }
  cout << ans;
  return 0;
}
