#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, k1, k2, i, counta = 0, countb = 0, a[100001], b[100001], maxa, maxb;
  string s;
  cin >> n >> k;
  cin >> s;
  k1 = 0;
  k2 = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == 'a') {
      counta++;
      a[k1++] = i;
    } else {
      countb++;
      b[k2++] = i;
    }
  }
  if (counta <= k || countb <= k) {
    cout << n << endl;
  } else {
    maxa = b[k];
    maxb = a[k];
    for (i = k + 1; i < k2; i++) {
      if (maxa < b[i] - b[i - k - 1] - 1) maxa = b[i] - b[i - k - 1] - 1;
    }
    if (maxa < n - b[k2 - k - 1] - 1) maxa = n - b[k2 - k - 1] - 1;
    for (i = k + 1; i < k1; i++) {
      if (maxb < a[i] - a[i - k - 1] - 1) maxb = a[i] - a[i - k - 1] - 1;
    }
    if (maxb < n - a[k1 - k - 1] - 1) maxb = n - a[k1 - k - 1] - 1;
    cout << max(maxa, maxb) << endl;
  }
  return 0;
}
