#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<vector<long long>> v(n, vector<long long>(2));
  long long a = 0, b = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'a') a++;
    if (s[i] == 'b') b++;
    v[i][0] = a;
    v[i][1] = b;
  }
  long long ans = 1, i = 0, j = 0;
  while (i < n) {
    long long c;
    if (!i)
      c = 0;
    else
      c = v[i - 1][1];
    while (j < n) {
      if (v[j][1] - c <= k) {
        ans = max(ans, j - i + 1);
        j++;
        continue;
      }
      if (v[j][1] - c > k) {
        break;
      }
    }
    i++;
  }
  long long res = 1;
  i = 0;
  j = 0;
  while (i < n) {
    long long c;
    if (!i)
      c = 0;
    else
      c = v[i - 1][0];
    while (j < n) {
      if (v[j][0] - c <= k) {
        res = max(res, j - i + 1);
        j++;
        continue;
      }
      if (v[j][0] - c > k) {
        break;
      }
    }
    i++;
  }
  cout << max(ans, res);
  return 0;
}
