#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
int solve(char c) {
  int l = 0, r = 0, chr = 0, bestWindow = 0;
  while (r < n) {
    if (chr <= k) {
      if (s[r] == c) chr++;
      r++;
    }
    if (chr > k) {
      if (s[l] == c) chr--;
      l++;
    }
    if (r - l > bestWindow) {
      bestWindow = r - l;
    }
  }
  return bestWindow;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  cin >> s;
  int a = solve('a');
  int b = solve('b');
  cout << max(a, b) << "\n";
  return 0;
}
