#include <bits/stdc++.h>
using namespace std;
bool is_palindrome(string s) {
  long long l = 0;
  long long r = (long long)s.size() - 1;
  while (l <= r && s[l] == s[r]) {
    l++;
    r--;
  }
  return l > r;
}
void func() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  string s;
  cin >> s;
  vector<long long> a, b;
  long long count = 0;
  char prev = 'x';
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == prev) {
      count++;
      ans = max(ans, count);
    } else {
      count = 1;
      ans = max(ans, count);
      prev = s[i];
    }
    if (s[i] == 'a') {
      a.push_back(i);
    } else {
      b.push_back(i);
    }
  }
  for (long long i = 0; i < a.size(); i++) {
    if (i == 0) {
      if (i + k < a.size()) {
        long long res = a[i + k];
        ans = max(ans, res);
      } else {
        ans = max(ans, n);
      }
    } else {
      if (i + k < a.size()) {
        long long res = a[i + k] - a[i - 1] - 1;
        ans = max(ans, res);
      } else {
        ans = max(n - 1 - a[i - 1], ans);
      }
    }
  }
  for (long long i = 0; i < b.size(); i++) {
    if (i == 0) {
      if (i + k < b.size()) {
        long long res = b[i + k];
        ans = max(ans, res);
      } else {
        ans = max(ans, n);
      }
    } else {
      if (i + k < b.size()) {
        long long res = b[i + k] - b[i - 1] - 1;
        ans = max(ans, res);
      } else {
        ans = max(n - 1 - b[i - 1], ans);
      }
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    func();
  }
  return 0;
}
