#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
long double pi = 3.1415926535897932384626433832795;
const int N = 2e5 + 10, lg = 2;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int c(int k, int n) {
  int nm = 1, dm = 1;
  while (k) {
    nm *= n;
    dm *= k;
    n--, k--;
  }
  return nm / dm;
}
int n, k;
string s;
int cnta[N], cntb[N];
int main() {
  cin >> n >> k;
  cin >> s;
  int res = 0;
  int ans = 0, l = 0, r = 0, cur = 0;
  while (r < n) {
    if (s[r] == 'a') {
      ans = max(ans, r - l + 1);
      r++;
      continue;
    }
    if (s[r] == 'b') {
      if (cur < k)
        cur++;
      else {
        while (l < n && s[l] != 'b') l++;
        l++;
      }
      ans = max(ans, r - l + 1);
      r++;
    }
  }
  l = 0, r = 0, cur = 0;
  while (r < n) {
    if (s[r] == 'b') {
      ans = max(ans, r - l + 1);
      r++;
      continue;
    }
    if (s[r] == 'a') {
      if (cur < k)
        cur++;
      else {
        while (l < n && s[l] != 'a') l++;
        l++;
      }
      ans = max(ans, r - l + 1);
      r++;
    }
  }
  cout << ans;
  return 0;
}
