#include <bits/stdc++.h>
using namespace std;
string a;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k, i, l = 0, r = 0, c = 0, ans = 0;
  cin >> n >> k;
  cin >> a;
  for (i = 0; i < n; i++) {
    if (a[i] != 'a') {
      if (c < k) {
        c++;
        r++;
      } else {
        while (l < n && a[l] != 'b') l++;
        l++;
        r++;
      }
    } else
      r++;
    ans = max(ans, r - l);
  }
  l = 0;
  r = 0;
  c = 0;
  for (i = 0; i < n; i++) {
    if (a[i] != 'b') {
      if (c < k) {
        c++;
        r++;
      } else {
        while (l < n && a[l] != 'a') l++;
        l++;
        r++;
      }
    } else
      r++;
    ans = max(ans, r - l);
  }
  cout << ans << endl;
  return 0;
}
