#include <bits/stdc++.h>
using namespace std;
long long modularExponentiation(long long x, long long n, long long MM) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % MM;
    x = (x * x) % MM;
    n = n / 2;
  }
  return result;
}
long long modInverse(long long A, long long MM) {
  return modularExponentiation(A, MM - 2, MM);
}
bool sortbysec(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second > b.second);
  else
    return a.first < b.first;
}
bool sortt(pair<long long, long long> &a, pair<long long, long long> &b) {
  return a.second > b.second;
}
bool sortbydiff(pair<long long, long long> &a, pair<long long, long long> &b) {
  return (a.first - a.second) > (b.first - b.second);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  long long a = 0, b = 0;
  long long ans = 0, count = 0;
  for (long long i = 0; i < s.size(); i++) {
    s[i] == 'a' ? a++ : b++;
    if (min(a, b) <= k)
      ans = max(ans, a + b);
    else
      s[count++] == 'a' ? a-- : b--;
  }
  cout << ans;
}
