#include <bits/stdc++.h>
using namespace std;
long long int n, k, i, j, l, counta, countb, maxm, flag, temp, val, arr[200000],
    brr[200000];
string s;
long long int BeautifulString(char ch) {
  j = 0, flag = 0, maxm = -1, temp = 0;
  for (i = 1; i <= n; i++) {
    if (ch == s[i]) flag++;
    if (flag > k) {
      j++;
      flag--;
    }
    if (ch == s[i] && s[i] == 'a')
      temp = arr[j];
    else if (ch == s[i] && s[i] == 'b')
      temp = brr[j];
    maxm = max(maxm, i - temp);
  }
  return maxm;
}
void Count(string str) {
  counta = 0;
  countb = 0;
  arr[150000] = {0}, brr[150000] = {0};
  for (i = 1; i <= n; i++) {
    if (str[i] == 'a') {
      counta++;
      arr[counta] = i;
    } else {
      countb++;
      brr[countb] = i;
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  cin >> s;
  s = '$' + s;
  Count(s);
  val = max(BeautifulString('a'), BeautifulString('b'));
  cout << val;
}
