#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
bool can(int x) {
  int qtda = 0, qtdb = 0;
  for (int i = 0; i < x; i++) {
    if (s[i] == 'a')
      qtda++;
    else
      qtdb++;
  }
  if (min(qtda, qtdb) <= k) return true;
  for (int i = x; i < n; i++) {
    if (s[i - x] == 'a')
      qtda--;
    else
      qtdb--;
    if (s[i] == 'a')
      qtda++;
    else
      qtdb++;
    if (min(qtda, qtdb) <= k) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  cin >> s;
  int ans = 1;
  int l = 1;
  int r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (can(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << endl;
}
