#include <bits/stdc++.h>
using namespace std;
int n, k, sum[100005];
char c;
bool check(int len) {
  for (int i = len; i <= n; ++i) {
    int dm = sum[i] - sum[i - len];
    if (len - dm <= k * 2 || dm + len <= k * 2) return 1;
  }
  return 0;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> c;
    if (c == 'a')
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1] - 1;
  }
  int L = 1, R = n, MID;
  while (L < R) {
    MID = (L + R) / 2;
    if (check(MID))
      L = MID + 1;
    else
      R = MID;
  }
  if (check(L))
    cout << L;
  else
    cout << L - 1;
}
