#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const long long N = 1e6 + 10;
const long long IM = 1e16;
const long long PI = 3.14159265;
void PV(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << " ";
  cout << "\n";
}
void IN(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
inline void PTN(long long n = 1, long long a = 0, long long b = 0,
                long long c = 0) {
  if (n--) cout << a << " ";
  if (n--) cout << b << " ";
  if (n--) cout << c << " ";
  cout << "\n";
}
inline void op() {}
string s;
long long n, k;
bool ck(long long l) {
  long long a = 0, b = 0, i, j;
  for (i = 0; i < l; i++) {
    if (s[i] == 'a') a++;
    if (s[i] == 'b') b++;
  }
  if (a + k >= l || b + k >= l) return 1;
  for (i = l; i < n; i++) {
    if (s[i] == 'a')
      a++;
    else if (s[i] == 'b')
      b++;
    if (s[i - l] == 'a')
      a--;
    else if (s[i - l] == 'b')
      b--;
    if (a + k >= l || b + k >= l) return 1;
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  op();
  long long i, j, x, y, u, l;
  long long tt = 1;
  {
    i = j = x = y = u = l = 0;
    cin >> n >> k;
    cin >> s;
    x = 1, y = n;
    long long ans = k;
    while (x <= y) {
      u = x + (y - x) / 2;
      if (ck(u)) {
        ans = u;
        x = u + 1;
      } else {
        y = u - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
