#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  string str;
  cin >> n >> k >> str;
  int l = 0, res = 0;
  unordered_map<char, int> m;
  for (int i = 0; i < n; i += 1) {
    m[str[i]]++;
    if (min(m['a'], m['b']) <= k)
      res++;
    else
      m[str[l]]--, l++;
  }
  cout << res << endl;
  return 0;
}
