#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  string str;
  cin >> n >> k;
  cin >> str;
  long long l = 0, r = 0;
  long long cntb = 0;
  long long ans1 = 0, ans2 = 0;
  while (r < n and l <= r) {
    if (str[r] == 'b') {
      cntb++;
      if (cntb <= k) {
        ans1 = max(ans1, r - l + 1);
        r++;
      } else {
        while (str[l] == 'a') l++;
        l++;
        r++;
      }
    } else {
      ans1 = max(ans1, r - l + 1);
      r++;
    }
  }
  ans2 = 0;
  r = 0, l = 0;
  long long cnta = 0;
  while (r < n and l <= r) {
    if (str[r] == 'a') {
      cnta++;
      if (cnta <= k) {
        ans2 = max(ans2, r - l + 1);
        r++;
      } else {
        while (str[l] == 'b') l++;
        l++;
        r++;
      }
    } else {
      ans2 = max(ans2, r - l + 1);
      r++;
    }
  }
  cout << max(ans1, ans2);
}
