#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int i = 0, j = 0;
  int freq[2] = {0, 0};
  int ans = 0;
  bool over = 0;
  while (j < n) {
    while (min(freq[0], freq[1]) <= k && j < n) {
      freq[s[j] - 'a']++;
      if (min(freq[0], freq[1]) > k) {
        over = true;
        break;
      }
      j++;
    }
    ans = max(ans, j - i);
    if (over) {
      while (min(freq[0], freq[1]) > k) {
        freq[s[i] - 'a']--;
        i++;
      }
      over = 0;
      j++;
    }
  }
  cout << ans;
}
